使用Selenium 2在页面上查找文本

thi*_*ple 14 groovy selenium

如何使用Selenium检查当前页面上是否存在给定的文本字符串?

Gro*_*eek 17

代码是这样的:

def elem = driver.findElement(By.xpath("//*[contains(.,'search_text')]")); 
if (elem == null)  println("The text is not found on the page!");
Run Code Online (Sandbox Code Playgroud)