I'm looking for a working implementation of this. The best I've come up with is:
public boolean isTextPresent(String string) {
for (WebElement e : drv.findElements(By.cssSelector("*"))) {
if (e.isDisplayed() && e.getText().contains(string)) {
return true;
}
}
return false;
}
A faster way to do it would be something like this:
public boolean isTextPresent(string str)
{
IWebElement bodyElement = driver.FindElement(By.TagName("body"));
return bodyElement.Text.contains(str);
}
It's in C# but it's the same concept. Getting the text of the body tag automatically returns the text of all the nested elements. The only thing I'm not sure about is if hidden elements are included or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With