user1254309
user1254309

Reputation: 21

Selenium - XPath element not found

I found the following XPath expression using FirePath and Firebug:

//div[@class='itudeBox floatDiv']/div[1]/div/text()[2]

This returns the correct value in Selenium.

But when I try the same in EclipseTestNG:

selenium.getAttribute("xpath=//div[@class='itudeBox floatDiv']/div[1]/div/text()[2]");

It shows an error "Element not found".

How can I fix this?

Upvotes: 1

Views: 6381

Answers (2)

Cliff Darling
Cliff Darling

Reputation: 225

Try this:

selenium.getText("xpath=//div[@class='itudeBox floatDiv']/div[1]/div");

Or:

selenium.getText("xpath=//div[@class='itudeBox floatDiv']/div[1]/div[2]");

The getText() method works on the element and I believe your XPath expression returns the text within an element.

Upvotes: 1

Rohit Ware
Rohit Ware

Reputation: 2002

Try out the below one to locate the element:

//div[text()='AD- Advice']
css=div:contains(“AD- Advice”)
//div[contains(text(),'AD- Advice')]

Upvotes: 1

Related Questions