The Advanced Features of Selenium

Explore advanced Selenium features, including relative locators, Chrome debugging, and scaling tests with cloud providers.

Selenium is a powerful and mature test automation framework, and with very little programming effort, we can perform many actions on a front-end web application. Modern websites are written with powerful web application frameworks, which enable developers to enrich their websites and add complex logic and components to their pages. Realizing the power of a test automation framework such as Selenium can help to automate and test with wide coverage of these advanced components.

Let’s start covering a newly added feature of Selenium 4 called relative locators.

Selenium relative locators

In previous versions of Selenium, it was quite challenging to identify an element on a web page, especially if there were other elements that were similar or when the web page was too crowded with UI elements. For that purpose, the Selenium community implemented a new feature that allows test developers to clearly specify an element location and a name relative to other elements on that page.

If we look at the Packt website under test, we see that there are three buttons on the upper viewport of that page. While each of these elements has unique text that describes them, all three buttons have the same className identifier (subscribe_cta). With Selenium 4, we can be very accurate in identifying each of them by utilizing relative locators:

Get hands-on with 1200+ tech skills courses.