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
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.