Automate your web logins
Selenium Searches
From the earlier park booking example, you saw that xte
and xautomation had some limitations when a variable list of options was presented. Luckily Selenium has a number of functions that can be used for searching HTML tags and text. Like the last example, the first step is to open the web page and inspect the structure manually (Figure 6).
For this example, the Inspector shows that each status entry in the list has a <div class="jss97">
that could have a Past, Available, Not Busy, or Full status. The top-level <div class="jss94">
has both the times and the status messages. Knowing the top-level div class
now makes it possible to search for the park's time slots and get the status of each of the times.
Figure 7 shows an example that searches for the first Not Busy time slot. As in the earlier xdotool
example, the time slot list needs to be clicked to open. In Python code, this is done by finding and then clicking on the timefield
object.
The key piece in this code is:
thetimes = find_elements_by_class_name("jss94")
This operation will build an array (thetimes
) of all the time slots with their status messages.
Next, a for
loop can examine each time slot. In this example, the code looks for the first time a time slot is Not Busy:
# Get the top level div thetimes = browser.find_elements_by_class_name("jss94") for itimes in thetimes: # Find the first "Not Busy" if "Not Busy" in itimes.text: print(itimes.text) itimes.click() break
Logic could be written for different conditions, like looking for time slots between 9 and 11am, and if none are found, then looking for time slots between 2 and 4pm.
Final Comments
After using the various methods discussed in this article, I found that:
- Often my apps written during off hours would not work during peak times because I had not accounted for the increased peak callup delays.
- The browser search dialog with
xte
/xdotool
was extremely useful because it allowed me to jump to specific areas of a web page, rather than tabbing to it. - Creating apps with
xte
orxdotool
is considerably easier than using Python with Selenium. I found that some web pages were incredibly complex, and it often took some time to find the required IDs that Selenium needed. - For large web entry pages, you can always create automated web logins by mixing and matching the
xte
/xdotool
utilities and Python. - Two huge advantages in using Selenium are being able to add some decision-making logic and
implicity_wait()
methods, which wait until the page is ready and is a lot more efficient than putting in a long sleep time.
Infos
- xautomation man page: https://linux.die.net/man/7/xautomation
- xdotool man page: https://man.cx/xdotool
- wmctrl man page: https://linux.die.net/man/1/wmctrl
- Selenium: https://en.wikipedia.org/wiki/Selenium_(software)
- Selenium downloads: https://www.selenium.dev/downloads/
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.