XPath – what is it and how to find it?

What is XPath?

XPath (XML Path Language) is simply a language for pointing the path to a selected element of an XML file (including, for example, HTML). It is the core element of the XSLT standard.
XPath is very common among testers, who use XPath in Selenium testing, among other things.

XPath paths can be divided into:

  • relative – //*[@id=”JHCk3y1nXqNO7OT8hot7iA”]/div[1]/h2
  • absolute – /html/body/div[1]/div[2]/div[3]/div[1]/div[2]/div/div[1]/h2

How to find XPath in Chrome?

  1. Right-click on the element XPath you want to find.
  2. Choose “Inspect”. Once opened, the console will point you to the appropriate HTML element.
  3. Right-click on the indicated HTML element.
  4. Select the “Copy” -> “Copy XPath” option.

How to find XPath in Safari on MacOS?

  1. Right-click on the HTML element whose XPath you want to find.
  2. Select “Inspect Element.” Once opened, the console will point you to the appropriate HTML element.
  3. Right-click on the indicated HTML element.
  4. Select the “Copy” -> “XPath” option.

Firefox – how to find XPath?

  1. Right-click on the HTML element whose XPath you want to find.
  2. Choose “Inspect”. Once opened, the console will point you to the appropriate HTML element.
  3. Right-click on the indicated HTML element.
  4. Select the “Copy” -> “XPath” option.

After following the above steps, the XPath for the selected HTML element is already in your clipboard 😉

Related posts