What is a dynamic XPath?

The standard way of writing XPath may not work if the element path on the webpage changes dynamically.

Let’s say there is a table whose rows are shown based on a data set, which can vary from time to time. Sometimes, it will have 4 rows, and other times, it will have 6 or 7.

Another example is when a node/element attribute’s value is always dynamic and keeps on changing with page reload; in that case, you simply can’t use an attribute’s value to identify the unique element reliably every single time.

How to handle dynamic XPaths?

Example HTML considered for demonstration

Let us consider an example. Take a look at the following HTML structure:

Get hands-on with 1200+ tech skills courses.