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:
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.