In WebDriver (Selenium 2), there is no predefined method for checking this. (In Selenium-RC isTextPresent("text") built-in method exist ) So we need to implement our own method to achieve this.
Let us consider you are searching for text "WebDriver"
boolean isTextPrest=false;
Method-1
isTextPrest=driver.findElement(By.tagName("body")).getText().contains("WebDriver");
Method-2
isTextPrest=driver.findElement(By.xpath("//*[contains(.,'WebDriver')]")).isDisplayed();
Method-3
Selenium sel=new WebDriverBackedSelenium(driver, "");
isTextPresent=sel.isTextPresent("WebDriver");
FYI : Method-1 will take more time than remaining (comparatively)
Happy Coding :)
Regards,
SantoshSarma
We can also use following code line.
ReplyDeleteisTextPrest = driver.getPageSource().contains("WebDriver");