Here are a few XPaths that take on the above form to identify the thumbnail preceding “How AI can save our humanity”. Retrieve all elements with the same tag name as the target element, then Retrieve the neighbor among those retrieved in step 1 using the neighbor’s index.įrom the neighbor, going forward or backward Retrieve the element using the text of its neighbor Each column in this form is explained as follows: Column No. This form assumes that a neighbor of the target element is robust and is identified by its text. This method is visually intuitive as it reflects the way users often identify a visible element on the user interface.Īn XPath (also called neighbor XPath) generated by the method follows the following form: 1 That is a simple but powerful idea behind the new locator method introduced in Katalon Studio. If an element cannot be consistently located using its direct attributes, then identifying it using its more robust neighbors. Neighbor XPath: An adequate form of XPaths for the above situations The remaining XPaths suffer the same problems we already discussed with the TED website. Some playback engine will automatically select the first element among those five, but some will not. The result is not surprising because indeed there are five Web elements with the tag in the company information section. (You can check this by opening Chrome and pressing Ctrl + Shift + I to open the Inspection Tool and search the XPath in the document – shown below). Unfortunately, this locator identifies five Web elements instead of a unique element as expected. The headquarters field is located by a relatively concise XPath. So using ID as a locator is not a good choice in this situation. However, you will later find out that it won’t because the ID is different every time you visit this page. You now can say that at least your test case will successfully locate this field. The website field is located by its ID, which seems to be a reasonable choice. Selenium’s examine the table above row by row. Suppose you want to verify Microsoft’s profile information, and you use Selenium to record by clicking on each of the fields to obtain the XPaths, here’s what you will get: Fields Take another example, Microsoft profile on Linkedin. In short, these locators are fragile and hard to read and maintain. Such an assumption contradicts reality, as described. If you look at these XPaths, or just at the last 3 characters, you will notice that they rely entirely on the assumption that the ordering of the video will not change. Therefore, it is no surprise that the first video today may be the third video tomorrow. TED is a fast-growing website with new contents being produced every day. But the main problem is that they are easily broken as they only work if the content is not changed. Selenium’s these XPaths can locate the element, they are too long and complex. Suppose you want to record a simple action of clicking on a thumbnail of a video, the one with “How AI Can save our humanity”, for example, you would get the following XPaths generated by Selenium: The screenshot below shows the website’s cards with each contain different items (text, image, link, etc.). Let’s look at ted.com, a website built using the EmberJS framework.
Cases where common locators are inadequate This advanced method produces new locators that are more maintainable and less vulnerable to changes in AUT than do Selenium and other test automation tools. In this article, we describe a brand-new and intelligent method introduced in Katalon Studio to automatically generate robust locators during the test recording phase. Hence creating and using correct and resilient locators are crucial to the success of Web UI test automation. An existing study showed that locators account for more than 70% of breakages in Web UI test scripts. Unfortunately, locators are easily broken or unable to identify the target element when the application under test (AUT) changes. A locator is a mechanism used by Selenium to identify an element during test execution. In Web UI automated testing, a primary concern for testers is high maintenance costs of test scripts, which are usually caused by unstable and broken locators.