我很初学者,使用Selenium和Java编写测试,有时我需要点击的Web元素被其他人覆盖,根据this现在 elementToBeClickable
只是检查它是否可见并启用。有什么办法可以解决这个问题吗?
最佳答案
elementToBeClickable
just checks that it's visible and enabled
这绝对是真的 - 预期条件并非基于实际情况 Element Displayedness - 但是,isDisplayed()
完全基于提到的 WebDriver 规范 - 在自定义预期条件中调用它:
public static ExpectedCondition<WebElement> isDisplayed(final By locator) {
return new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver driver) {
WebElement element = webDriver.findElement(locator);
if (element.isDisplayed()) {
return element;
}
}
};
}
用法:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(isDisplayed(By.id("myid")));
关于java - `elementToBeClickable` 只是检查它是否可见并启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34601246/