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
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.