[英]Check for element to be clickable without an explicit wait time
As stated by the Selenium Documentation we never should mix up explicit and implicit wait times: 正如Selenium文档所述,我们永远不应该混淆显式和隐式等待时间:
WARNING: Do not mix implicit and explicit waits. 警告:不要混合隐式和显式等待。 Doing so can cause unpredictable wait times. 这样做会导致不可预测的等待时间。 For example setting an implicit wait of 10s and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds. 例如,设置10秒的隐式等待和15秒的显式等待可能导致20秒后发生超时。
I've set a implicit wait time of 5000 ms. 我设置了5000毫秒的隐式等待时间。 At the end of some Browser interaction I just want to verify whether the required links are clickable. 在某些浏览器交互结束时,我只想验证所需链接是否可点击。
I know that this can be done by using ExpectedConditions
, but this implies an explicit wait time as in the example below. 我知道这可以通过使用ExpectedConditions
来完成,但这意味着明确的等待时间,如下例所示。
protected PageNewDocument isElementClickable(WebElement element)
{
(new WebDriverWait(driver, 1)).until(ExpectedConditions.elementToBeClickable(element));
return this;
}
How can I check for elements to be clickable without the definition of an explicit wait time? 如何在不定义明确等待时间的情况下检查可点击的元素?
Answered a similar question here the other day. 前几天在这里回答了类似的问题。 This method waits for the page to be loaded before returning true. 此方法在返回true之前等待页面加载。 So your elements should be clickable then. 因此,您的元素应该是可点击的。
private static WebDriverWait wait = new WebDriverWait(driver, 60);
private static JavascriptExecutor js = (JavascriptExecutor) driver;
public static void waitForPageLoaded() {
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
Boolean res = (js.executeScript("return document.readyState").equals("complete"));
System.out.println("[DEBUG] waitForPageLoaded: " + res);
return res;
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.