Selenium, SikuliX and Social Network 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 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 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:
That’s how Selenium IDE 2.9.1 looks:
As a test task for Selenium I chose to automate posting to my Social Network page.So, press the red button and perform some actions in browser tab. Selenium will add the commands automatically.
I could use this script to scan Social Network 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.
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 Social Network 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, Social Network don’t add an image for the blog post at the first time. The scripts reloads current page and repeats the operation.
On second time Social Network 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.
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 Social Network API would be much preferable.
Hi! My name is Alexander and I am a Vulnerability Management specialist. You can read more about me here. Currently, the best way to follow me is my Telegram channel @avleonovcom. I update it more often than this site. If you haven’t used Telegram yet, give it a try. It’s great. You can discuss my posts or ask questions at @avleonovchat.
А всех русскоязычных я приглашаю в ещё один телеграмм канал @avleonovrus, первым делом теперь пишу туда.
Pingback: Automating Opera browser with Selenium WebDriver and Python | Alexander V. Leonov
Pingback: First look at Tenable.io Web Application Scanner (WAS) | Alexander V. Leonov