我正在编写一些使用selenium chrome driver的自动化测试。我试图编写一个可重用的方法,该方法将显式等待元素出现,然后在其他类中调用此方法。看起来很简单,但它没有做我想要的事情。这是我拥有的方法。
public String waitForElement(String item) {
WebDriverWait wait = new WebDriverWait(driver,30);
WebElement element = wait.until(
ExpectedConditions.elementToBeClickable(By.id(item)));
return item;
}
然后我调用这个方法,并像这样传递一个参数:
waitForElement("new-message-button");
那似乎不起作用,有人能提供一些见解吗?
element
是否被找到了? - anotherdave