11 Unique Ways to Create Dynamic XPath in Selenium

Single Slash

A single slash is used to create an XPath with an absolute path

Double Slash

A double slash is used to create XPath with a relative path, which means that the XPath can begin selection from anywhere in the document.

Single Attribute

The syntax could be written in two ways,HTML Tag inclusion or exclusion. If you want to exclude HTML tags, you must use *.

Using contains()

Contains() is a method for identifying an element that changes dynamically and when familiar with some part of the element’s attribute value

Use of text ()

This mechanism is used to find an element based on a web page’s text.

Using position()

The element is chosen from among all input elements based on the position number provided.

Using an index

We could get to the nth element by putting the index position in square brackets.

Using previous XPath axes

Except for ancestors, attribute nodes, and namespace nodes, this selects all nodes that appear before the current node in the document.