Writing web automation without having good knowledge of selector strategies is like going 🚶 to a place 🌍 whose address we don’t know.
Selectors are addresses of web elements. Thus if we want to perform an action on a web element, we first have to locate 🔍 the address of that element, and only then perform an action on it. Just as we can get an address of a place in multiple methods, in the same manner we can also locate a web element with different types of selector strategies.
There are 8 kinds of selectors (as shown in the image below) 👇
As a test automation developer, you probably know that choosing the right Selenium selector strategies can be a painful and repetitive task. You will need to work with Chrome Developer Tools, inspecting and exploring the right element strategy, copying it to your code and then boom 💣 The next time you will run the test it will break! 💔 And what about the XPath syntax? That can be a pretty painful craft in itself too, especially for folks just starting out their automation testing journey – trying to write the syntax needed to be tested, only to have characters in the wrong place or even at a blank space… 😥
On average, most of us waste a very good amount of time (~1 min) 🕑, just to write one XPath or cssSelector:
Imagine an automation tester writing more than 100 selectors per day, how much time would they be wasting just in writing selectors 🗑️✍️? We are wasting this much time because:
- We copy-paste attribute values from the DOM while writing selectors like XPath.
- We have to figure out what is wrong and missing in our selectors while building them manually.
- We need to manually look for what kind of element it is like SVG or inside Shadow DOM, iFrame, Frame, etc.
This entire process is like writing code on Notepad, while we have so many smart editors like IntelliJ…
But not anymore ⚡️✌️ Nowadays, we have great options to achieve exactly that, but effortlessly.
TestProject revolutionizes the automation world with AI-powered self-healing test automation, which entirely focuses on Selenium selectors. It’s a first of a kind and the only FREE tool available today for Selenium powered by AI capabilities.
Elements tend to change frequently, leading to failures and flakiness of our automated test cases. But with TestProject’s smart algorithms, each element is identified not by a single selector but rather with multiple optimized selectors that are prioritized for you.
You don’t need to spend time looking for the best element selector strategies! And even more than that, you don’t need to be an expert with XPath or cssSelectors at all. You can simply perform the action you want, and TestProject’s Smart Test Recorder will automatically build for you 3 to 10 different element selectors for each element you are interacting with. TestProject handles even the toughest use cases, such as iFrames and purely dynamic elements 🔥🔥🔥
Once the element is located by multiple Selenium locators, TestProject’s AI will try to fix the broken selector in runtime and in some cases autonomously predict how the element selector should look after a specific action is preformed.
You can view the selectors that were chosen for each element and their priority by clicking on the “magnifying glass”. You can also change the default priority of each selector by moving it up or down as per your needs.
Feeling like an XPath Master and want to add your own customized selectors? Simply click on the Add locator + icon and add your custom selector (one or more) in addition to the existing ones, to make your automation even more robust 💪
There are many tools that will help you to build custom and optimized selector strategies, and I would like to show you how SelectorsHub does it very easily.
With the features like auto-suggest attributes while typing, error info for invalid selectors, shadow DOM, SVG, iFrame, etc… SelectorsHub can save you a huge amount of time and help you to learn a lot more about XPath as well as DOM. And it is an absolutely FREE, community product. Simply go ahead and download it from here: Download link.
Once these selectors are built using SelectorsHub, you can simply copy-paste them to TestProject in the Add locator text box, and you’ll be all set with the best Selector Strategy possible 🚀
✨👉 Save a seat & join me live on YouTube on Sunday 15 November to learn all about Selector Strategies @ 8:30 AM EST / 2:30 PM CET / 7:00PM IST!