Saturday, August 7, 2010

XPath and Selenium Locator Information

I often need to use a relative XPath to locate elements in Selenium. A few reasons to use relative XPath:
  1. The ID of the element changes every time you go to the page.
  2. You suspect the element could change location in the future and the locator recorded by Selenium IDE is too ambiguous to handle changes in the future.
Here's some excellent information on Locators in Selenium: http://seleniumhq.org/docs/02_selenium_ide.html#locating-elements

I often refer to http://www.w3.org/TR/xpath/ , particularly sections 2 Location Paths, 2.2 Axes, 2.5 Abbreviated Syntax.