The following is a collection of notes on how to automate any website with hopefully zero knowledge about programming but with some knowledge on web technologies such as HTML and CSS (XPath, CSS selectors, and so forth.). The goal is to generate a workflow visually, such as logging in to a website, or clicking some buttons on a website, and then automate the recorded process on a server.
selenium-side-runner
and a webdriver of choice must be installed, for this example, the Google Chrome webdriver will be used.Assuming that nodejs is installed on the machine that will playback the workflow, the following commands install the selenium side runner:
npm install -g selenium-side-runner npm install -g --unsafe-perm=true chromedriver
The –unsafe-perm=true
parameter is required in case an error is received when trying to install the Chrome driver.
apt-get install xdg-utils
Now the following requirements should have been installed:
selenium-side-runner
, chromedriver
and Google Chrome on the machine that will execute the workflow (server)This step is self-explanatory for the most part. Clicking the Selenium IDE addon button will launch a new window for the Selenium IDE. The principle is easy to grasp: you specify a website URL to automate, press the record button, perform a number of actions on that website (clicking buttons, filing in forms, etc.) and then play back the script to check that the script is performing all the actions properly.
In case the script fails to start at the very beginning, simply insert a new command at the very beginning of the script. Similarly, in case the Selenium IDE indicates an error mentioning CSP, on Firefox this error can be bypassed by going to about:config
and setting security.csp.enable
to false
.
Here is a screenshot of an example script used to log-in to www.myanonamouse.net:
As can be observed, all the commands are listed as the script has been recording and if the play button is pressed, the script will perform all commands one after the other.
Once a script has been generated and tested to be working properly, the script can be saved by clicking on the diskette button to a file ending in .side
(for example www.myanonamouse.net-login.side
) that has then to be transferred to the machine that will perform the automation.
With the side script transferred to the machine that will run the automation, in this example, www.myanonamouse.net-login.side
, the script can then be executed headlessly using the Google Chrome web driver. For example, issue:
selenium-side-runner -c "goog:chromeOptions.args=[--headless,--nogpu,--no-sandbox] browserName=chrome" www.myanonamouse.net-login.side
where:
www.myanonamouse.net-login.side
is the script transferred from the previous stepNote that due to security restrictions, the Google Chrome webdriver will only run as a regular user on Linux. Running the script as the root user will generate errors that will lead to the Chrome webdriver to fail.
The script should now run and perform all the steps in the background without opening any visible browser windows. After running, selenium-side-runner
will display some statistics such as whether the script ran successfully and the time it took for the script to run.
Assuming that a Selenium IDE side-script named www.myanonamouse.net-login.side
exists at /opt/myanonamouse/www.myanonamouse.net-login.side
, the following script can be placed under /etc/cron.weekly
in order to run the Selenium IDE script once a week:
#!/bin/bash # Restart the script as an user via su. if [ "$(id -u)" -eq 0 ]; then # exec replaces current shell exec su myanonamouse "$0" -- "$@" fi # Run the Selenium side script. cd /opt/myanonamouse selenium-side-runner \ -c "goog:chromeOptions.args=[--headless,--nogpu,--no-sandbox] browserName=chrome" \ /opt/myanonamouse/www.myanonamouse.net-login.side 2>&1 2>/dev/null >/dev/null