Skip to content

Need and Use of XPath

XPath

Automating a Web application having dynamic Id’s has become a great challenge. Dynamic IDs are those which are automatically generated ID attributes attached to any web element such as buttons, text-fields and labels. They typically look like some identifier text combined with an auto-incremented number like : ext-gen216, ext-comp216, 01rj0000000XHmF_Tab.

Generally these IDs are generated sequentially in an application. They may change from session to session, or even from window to window.

One of the biggest challenge with dynamic IDs is maintaining scripts between versions and even between different runs.




This challenge can be conquered using an XPath.

Use of XPath

XPath is designed to allow the navigation of XML documents, with the purpose of selecting individual elements, attributes, or some other part of an XML document for specific processing. There are various ways to build an XPath. Below is the screen capture for a basic XPath.


An XPath can be broadly classified into two types.

1.Absolute XPath
  •   html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/li[10]

2.Relative XPath
  • //li[@class='wt-Community_Theme']//a[text()='Community Themes']

Feedback and Knowledge Base