4

As stated by the Selenium Documentation we never should mix up explicit and implicit wait times:

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.

I've set a implicit wait time of 5000 ms. 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.

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?

My-Name-Is
  • 4,814
  • 10
  • 44
  • 84
  • what is issue to use implicit wait? – Helping Hands Apr 30 '15 at 08:43
  • @HelpingHands You mean, what's the purpose of an implicit wait time? Some content get's reloaded dynamically, hence it may not be availaible immediately due to delays. With an implicit wait time I don't have to take care about dynamic content. – My-Name-Is Apr 30 '15 at 08:46
  • No , I mean you said you are using implicit wait time of 5000 ms so is that not working? – Helping Hands Apr 30 '15 at 08:54
  • @HelpingHands Yes, it works. What I need is sth. like: `boolean clickable = driver.isElementClickable(element);` – My-Name-Is Apr 30 '15 at 08:56
  • So you want to get return only YES/NO? OR you want to check if element is clickable or not? during wait? – Helping Hands Apr 30 '15 at 08:57
  • @HelpingHands Exactly! But just finding the element via: `WebElement findElement(By by)` isn't enough. A check for `isClickable` is required which actually implies that the element is availaible in the DOM – My-Name-Is Apr 30 '15 at 09:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76618/discussion-between-helping-hands-and-my-name-is). – Helping Hands Apr 30 '15 at 09:07

1 Answers1

0

Answered a similar question here the other day. This method waits for the page to be loaded before returning 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;
            }
    });
}
Community
  • 1
  • 1
Cathal
  • 1,318
  • 1
  • 12
  • 19
  • 2
    Yes that's correct, but you still define an explicit wait time here: `private static WebDriverWait wait = new WebDriverWait(driver, 60);` – My-Name-Is Apr 30 '15 at 08:54