No votes yet.
Please wait...

Almost every major product company has test engineers on its staff who supervise the creation of new automated end2end tests in Selenium, Katalon Studio, etc. This task seems easy, especially with the necessary expertise. But in practice, enabling environment makes this process really difficult. And, in particular, there are difficulties with XML path languages (to write the correct test selectors).

XPath

XPath

There is a notion that XPath is something extremely complex and suffused with conceptual syntax. And some IT communities of automated QA engineers strongly doubt the good speed of XPath search. But in practice, everything turns out not so unambiguously. We can say that it is absolutely not so. And to deal with this, we’ll analyze the advantages of XPath and its shortcomings.

Cons

All the XPath selectors are undescriptive
Such an opinion appears after using plugins for the browser and classic web browser tools for search based on XPath. And it’s really so. For example, some sort of selectors (//div[1]/div[2]/ul/li/a) aren’t promising.

XPath cannot solve absolutely all issues
An illustrative example: with XPath, you cannot make selectors for pseudo-classes or Shadow DOM content.

The speed of XPath selectors may seem really slow for someone
You can haggle over this for a long time but considering the total time it takes to run the UI test, the actual difference in the speed of the selector is not very significant.

Pros

Search by the text of the selected item
First of all, when we get a web application to test, we see text. This text can be on the buttons, drop-down list boxes, and even in the links. If parameters of such elements can be modified, the text will probably stay the same.

All this clearly demonstrates the fact that with the help of XPath you can search for elements where the text is variable. Also, this feature allows you to develop selectors for building complex tables. For example, this option will be useful if the user needs to select cell X in row Y, and the column and row can only be found by text, given that the row and column number can change.

A set of built-in functions
Such parameters as a sibling, normalize-space(), and others in combination with a logical operator (for example, or and not) make it possible to develop flexible and efficient locators.

To Conclude

In the traditional sense, XPath is similar to modern programming languages: a well-crafted XPath selector is easy to read, we can tell from its appearance what specific element is being referred to. This makes interaction with XPath extremely convenient, increases the speed of solving typical problems, and, consequently, minimizes the time for software development and testing.

Leave A Comment