单击链接会触发创建新元素的操作。但是,在单击返回后调用 driver.findElement(By.id(""))
找不到它。
我尝试了以下代码来等待元素出现。
wait.until(new ExpectedCondition()
{
public Boolean apply(WebDriver webDriver) {
System.out.println("Searching ...");
return webDriver.findElement(By.id("itemType1")) != null;
}
});
但直到超时我仍然找不到它。
最佳答案
您也许可以使用 element.isDisplayed()
所以这样做:
WebElement jrnrText = driver.findElement(By.id("id"))
if(jrnrText.isDisplayed()){
wait.until(presenceOfElementLocated(BY.id]("id")))
}
Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) {
return new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(locator)
}
}
}
关于java - selenium2 webdriver找不到javascript新创建的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6148782/