Reputation: 21
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 Eclipse → TestNG:
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
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
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