aradhak
aradhak

Reputation: 836

WebDriver - find text corresponding to an element

The requirement would seem silly but I would like to see if we can automate verification of elements in the UI.

Req : I need to assert that the input element corresponding to "Name : " field is a textbox.

Using Selenium RC, I could do :

assertTrue(selenium.getAttribute("//label[normalize-space(text()='Name:')]/following-sibling::input@type").equals("text"))

This will work using webdriver as well but do we have a simpler approach?

Upvotes: 0

Views: 92

Answers (1)

Farlan
Farlan

Reputation: 1900

its a little easier to read in webdriver:

assuming selenium is your driver object, you can do something like this:

String elementAttribute = selenium.findElement(By.xpath("//yourXpathHere")).getAttribute("Type");
if (elementAttribute.equals("text") //success!
else //fails!

Upvotes: 3

Related Questions