Selenium, SikuliX and Facebook posting

The last post was about SikuliX. It’s fair to say that it’s not optimal for web applications automation. For such applications, it’s better to use something, that will natively work with your web-browse. The first solution that comes to mind is, of course, Selenium.

Selenium is a portable software-testing framework for web applications. Selenium provides a record/playback tool for authoring tests without the need to learn a test scripting language.

This app is released under the Apache 2.0 license and is a very common tool for Quality Assurance (QA). It can be also used in Information Security. For example, you can upload Selenium scripts in Qualys WAS (Web Application Scanner)  to help scanner in performing some complex operations, for example in authentication on the website.

Selenium Upload script in Qualys

Selenium is available in a form of two products: Selenium WebDriver for some hardcore automation and web-browser plugin Selenium IDE, which will help you to create and run scripts. I chose Selenium IDE.

Selenium types

Selenium installation

You can download Selenium IDE plugin for Firefox here: https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/ (please be careful, there are a lot of plugins with the similar names in the mozilla marketplace)

I also needed to install “Selenium IDE: Flow Control” addon because it fixes some errors in js processing https://addons.mozilla.org/en-US/firefox/addon/flow-control/

After installation in Firefox you can find Selenium IDE in Tools menu:

Selenium New Firefox Addon

That’s how Selenium IDE 2.9.1 looks:

Selenium IDE

As a test task for Selenium I chose to automate posting to my Facebook page. I created a page https://www.facebook.com/avleonovcom/ and wanted all ~60 posts from my blog to be there.

Warning! Using Selenium for this task is pretty silly. If you need to post something to Facebook automatically, you should try Facebook Instant Articles and Facebook Graph API first. Selenium and SikuliX here are just for example!

So, press the red button and perform some actions in browser tab. Selenium will add the commands automatically.

Facebook Selenium

I could use this script to scan Facebook with Qualys WAS. It makes authentication perfectly. But, with there were some problems with posting. I just couldn’t make Seleninum to press on “Write something” and input the message. Fiasco.

Facebook write something

Last thing about Selenium – you can export scripts from Selenum IDE in the form of python script:

Open the .htm script in Selenium IDE.
Select File > Export Test Case As > Python – Selenium RC. A .py file extension associates the file with Python. …

SikuliX once again

So, when I couldn’t post anything in Facebook with Selenium, I decided to use SikuliX once again. SikuliX is of course the last option, when you can’t or don’t want to understand how application works, but need to automate it somehow. This time I deployed it in Virtualbox, so it was possible to switch off mouse integration, and the script worked in virtual machine not disturbing me in any way.

I parsed my website content in this form “URL|Description Tags”:

https://avleonov.com/2017/02/09/whats-actually-new-in-tenable-io-vm-application/|My last post was about the structure [...] on new features.According to the public interface [...] #dashboards #NASL #Nessus #PVS #Tenable #Tenableio
https://avleonov.com/2017/02/13/sikulix-the-last-chance-for-automation/|This post I will publish in the API section of my blog. [...] #gmail #jar #java #jython #python #Sikuli #SikuliX

Each post on a separate line. If you want to use some text in Type function of SikuliX, you should clean it from all unusual characters. This function is pretty capricious. So, I converted my text in latin charset with iconv.

As you can see, I work with file in SikuliX like in usual python script. I also can split the lines and make substitutions in lines with re.

How it all works. I open the Posts page manually and launch SikuliX script. Script inputs url of my blog post in “Write something” entry field. As a rule, Facebook don’t add an image for the blog post at the first time. The scripts reloads current page and repeats the operation.

facebook SikuliX script 1

On second time Facebook finally gets images for the blog post, script deletes url from the entry field and adds description of the post. Then script switches off all images in illustrations except the first one, presses the Post button and repeats all operations for the next blog post.

facebook SikuliX script 2 facebook SikuliX script 3

The script is pretty stable, but it may fall if there are some unusual symbols in content, that SkuliX can’t type, sometimes web-browser also may freeze and Sikulix won’t be able to find the element before the timeout. In such cases I was need to delete post lines that were already published from posts.txt and relaunch the script. But, I once again want to repeat, that making this posting using Facebook API would be much preferable.

One thought on “Selenium, SikuliX and Facebook posting

  1. Pingback: Automating Opera browser with Selenium WebDriver and Python | Alexander V. Leonov

Leave a Reply

Your email address will not be published. Required fields are marked *