简体   繁体   English

在没有明确等待时间的情况下检查要点击的元素

[英]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.

相关问题 元素在提到等待的时间之前可见,所以隐式/显式等待是否仍然等到提到的时间或单击 - Element visible before the time mentioned for wait so Will the implicit/Explicit wait still wait till the time mentioned or click Selenium 等到元素可点击 - Selenium not wait to element to be clickable 即使我等待30秒,元素也无法点击 - Element cannot be clickable even I wait the element clickable for 30 seconds 如果所定位的元素为“文本”,则显式等待不起作用 - Explicit wait is not working if the element located is of 'text' 隐式/显式等待不等待指定的时间 - Implicit / explicit wait not waiting for specified amount of time Selenium Webdriver等待,元素不可点击异常 - Selenium webdriver wait, Element not clickable exception 如何使用Selenium Webdriver等待元素不可单击? - How to wait for an element NOT to be clickable using Selenium Webdriver? “隐式等待”等待元素可单击,显示或可见 - “Implicit wait” waiting for element to clickable, displayed or visible 检查 Selenium Java 中的元素是否可点击 - Check if element is clickable in Selenium Java 如何检查按钮是否在java,selenium webdriver.ps中可点击:检查是否可点击不要等到它可点击 - how to check if a button is clickable in java,selenium webdriver.ps:check if clickable not wait untill it is clickable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM