Getting Element Paths for Selenium UI Tests

How Can We Help?

Getting Element Paths for Selenium UI Tests

< Back

If you are writing your own Selenium tests, or need to add/edit a step in your tests generated by Selenium IDE, you’ll need to know how to get the path of any particular element. This can be done in any browser, but for this example we’ll use Chrome. The steps in other browsers will be almost identical.

First, find the element you want to get the path of, right click on it, and click Inspect.

 

 

The Elements tree will then open in your browser. The element you selected should be highlighted in the tree, and mousing over it should highlight it in the browser.

 

 

Right click on the element you want in the Elements tree, and mouse over Copy. You will get a few options of path to copy:

 

 

Each option is useful for different reasons:

  • Copy selector will give you the CssSelector path to the element. You can use driver.FindElement(By.CssSelector(“<the copied path>”)) to option to the element.
  • Copy JS path will give you a javascript snippet to point to the element, useful if you’re using a javascript script in your test.
  • Copy XPath will give the truncated XPath to the element. You can use driver.FindElement(By.XPath(“<the copied path>”)) to point to the element.
  • Copy Full XPath will give you the long version of the XPath. This version is the most accurate, but its also difficult to read, so its best used as a last result. You can also use driver.FindElement(By.XPath(“<the copied path>”)) to point to the element.

 

Comments are closed.

This is the legacy version of the XMPro Documentation site. For the latest XMPro documentation, please visit documentation.xmpro.com

X