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 the nth element with CSS

There are times where we need to find the nth element after a parent element on the page. In the XPath examples, we looked at the second input after the div with the class leftdiv. The XPath looked like this: xpath=//div[@class='leftdiv']/input[2]. To find the second to nth element we will need to use pseudo classes. Pseudo classes are used to add special effects to selectors. In this case we are going to use :nth-child for the first example.

  1. Open Selenium IDE.
  2. Navigate to http://book.theautomatedtester.co.uk/chapter2.
  3. Type css=div#divinthecenter *:nth-child(3). This will find the same as xpath=//div[@class='leftdiv']/input[2].
  4. Click on the Find button.

What just happened?

Unfortunately Selenium ...

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