O'Reilly logo

Selenium 2 Testing Tools Beginner's Guide by David Burns

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – finding elements by direct XPath

Instead of using the //, you can use a single / but you will need to make sure that the first node in your query is HTML. Let's see an example of this:

  1. Open Selenium IDE.
  2. Navigate to http://book.theautomatedtester.co.uk/chapter2.
  3. Type xpath=/html/body/div[2]/div[3]/input into the Target input of Selenium IDE.
  4. Click on the Find button.

What just happened?

The previous locator will have found the same element as before. This type of XPath query will find the element fractionally quicker but if your UI is going to change, it may fail if the element is moved into a different area of the page. One thing to really note is that XPath locators can be extremely fragile. They can find what you want but the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required