Implement Java Interface in Ruby Selenium DSL I
Jan 07

When element doesn’t contain any id and name, using xpath to find the element is very important for writing selenium test. I list some sample locate for the element which doesn’t contain id or name.

1. get the link with the link text<a href=”link url”>Link Text</a> -> link=Link Text

2. get element with the element text

<a href=”link url”>Link Text</a> -> //a[text()='Link Text']

3. get element with part of the element text

<a href=”link url”>Link Text</a> -> //a[contains(text(), 'ink Tex')]

4. get element with an attribute

<a href=”link url”>Link Text</a> -> //a[@href='link url']

5. get element with two attributes

<input type=”text” value=”value”/> -> //input[@type='text' and @value='value']

XPather is a firefox plugin help you to find the xpath.

There is more element locators document to be found on Selenium Doc

One Response to “Selenium Element Locators”

  1. Michael Says:

    Nice! Thanks!

Leave a Reply