Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify a Text present in the loaded page through WebDriver

I need to verify a Text present in the page through WebDriver. I like to see the result as boolean (true or false). Can any one help on this by giving the WebDriver code?

like image 261
kranthi kumar Avatar asked Nov 05 '12 06:11

kranthi kumar


1 Answers

As zmorris points driver.getPageSource().contains("input"); is not the proper solution because it searches in all the html, not only the texts on it. I suggest to check this question: how can I check if some text exist or not in the page? and the recomended way explained by Slanec:

String bodyText = driver.findElement(By.tagName("body")).getText();
Assert.assertTrue("Text not found!", bodyText.contains(text));
like image 199
Ricardo Vila Avatar answered Dec 08 '22 10:12

Ricardo Vila