New feature: SofySense – Manual test case & test results AI generator to help you speed up your testing process. Try it today.  

Sofy launches product feature suite to deliver effortless test maintenance and ensure continuous precision – learn more.

sofy logo
Image: Sofy

Considering XPath and Automated Testing

What exactly is XPath? What does the contemporary mobile app testing landscape and its shift toward no-code solutions mean for XPath and you?

In the mobile app testing space, automated testing can be a QA teams not-so-secret weapon for saving time.

That is, when it’s done right.

You see, when a new tool or method appears on scene to make more reliable more reliable test automation, it’s worth checking it out and seeing how beneficial it will be to your unique needs. 

XPath provides a solution that can help you develop more reliable testing automation without having to learn more complex languages. It works with XML, but doesn’t have the same syntax, making it more flexible, and it can be used with both HTML and XML pages.

Since XPath has gotten a lot of attention this article will provide a bit of detail about what it is exactly before we go into how to use it to create reliable test automation. XPath can be used for a number of different parts of the development process, so we’ll just focus on how it is used for automation testing.

What is XPath?

First introduced in 2003, XPath has been around for about 20 years. Over that the past few decades—when mobile apps themselves saw tremendous evolution and change—XPath has evolved right beside mobile app automation testing. Originally called XML Path Language, XPath is a part of the XSLT standard, and its syntax allows its users to easily navigate XML documents to find specific attributes and elements. 

XPath features a library that provides all standard functions. It can be used within a wide range of other languages, such as C, C++, Java, JavaScript, PHP, and Python. However, XPath is mostly used in XSLT. XPath functions in a way that is similar to URLs, employing a path notation to move through XML hierarchical structures. By avoiding XML syntax, XPath is able to better scroll through URIs and XML attributes. 

XPath is similar to SQL and XQuery in how it’s used. When you want to search through an XML document, you enter the targeted attribute or element as an XPath expression. It will go through the document to locate and extract the desired information.

A gear surrounded by arrows, implying the concept of automation.
Image: Sofy x nexusby, Shutterstock


Use of XPath in automated testing

If you’ve been a tester for any amount of time, you know that one of the biggest and most annoying issues to manage is how often attributes and elements change. There are upgrades that change the name or location of the components, updates that remove them, and releases that add new ones that must be tracked. All in all, it’s time consuming and definitely not something most of us enjoy having to contend with on a regular basis. 

Most of these have to be tested with each patch, upgrade, or release, which can be incredibly tedious. Especially given how frequently HTML and HTML changes roll out, this can be infuriatingly monotonous because of how often you may need to test and assess changes. This is why XPath can be incredibly beneficial. Since you may not have all of the details you need to find an attribute or element (most notably their exact name and exact location), you have several options for how you will test those attributes and elements. 

Depending on the type of XPath you use, the testing can locate one of the annoying attributes or elements that needs testing. When you consider how many you’re likely to need to test to make sure they haven’t changed, you can see how XPath can make automated testing much easier.

The caveat is that it has to be done correctly to work. If you don’t set it up properly, the testing will either fail or result in a passing status without actually performing testing in a correct manner.


To offer the kind of flexibility needed to find elements, there are three different types of XPath:

  • Absolute Xpath is used to locate specific attributes and elements based on the name and exact location. It is the longest and requires you to know exactly what you are looking for to be successful.
  • Relative Xpath is used to locate attributes and elements based on their relative location to something else on the page. This means that you need a stable, reliable target for your automation testing to be successful.
  • Exact XPath is used if you know the specific attributes or elements you need to locate it on the page.

Note that each of these has its own strengths and weaknesses, which we’ll cover in a future blog update.

XPath and Sofy

If you’re new to coding, all of this will sound quite complex. Knowledge of XPath is great but understanding code is not necessary for approaching modern no-code app testing platforms like Sofy. In fact, with Sofy, you don’t need to know a single line of code. XPath has played a vital role in mobile app testing over the past few decades, but abstraction marches on, and moving toward no-code is the natural next step in maximizing the efficiency and quality of your releases.

Disclaimer: The views and opinions expressed above are those of the contributor and do not necessarily represent or reflect the official beliefs or positions of Sofy.