我正在尝试找到最干净的代码来等待特定字符串出现在页面中。我现在拥有的最好的就是相当笨重
new Wait() {
@Override
public boolean until() {
return !webDriver.findElement(By.tagName("html"))
.getText().contains("please choose another");
}
}.wait("wait failed!", 60000);
有更优雅的方法吗?
最佳答案
如果这确实是您想做的事情,那么
webDriver.findElement(By.xpath("//*[contains(text(),'please choose another')]"));
带有 Implicit wait对我来说似乎更好一点(从“干净代码”的角度来看),因为它只是一行代码。
关于java - 在 Selenium 2/Java 中等待条件的最简洁方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10142709/