RE: Pulling text from DIV element using Selenium/Java

Answered

The text is contained in a DIV element:
<div class=”messageText”>No matches found</div>

The CSS path is:
//#searchResultsWarningMessageBox > table > tbody > tr > td.messageCell > div

The code I have is:
WebElement txtMsg = driver.findElement(By.cssSelector(“#searchResultsWarningMessageBox > table > tbody > tr > td.messageCell > div”));
txtMsg.getText();

I keep gettingĀ  .. no such element. Any ideas or hints?

Richard Allen Train Asked on September 24, 2014 in Selenium WebDriver.
Add Comment
3 Answers
Best answer

Hi Richard,

Try getAttribute(“innerHTML”) on the webelement.

Thanks
Virender

Professor Answered on September 24, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.