2

There have been questions on the difference between implicit and explicit wait in Selenium WebDriver.

What is difference between Implicit wait Vs. Explicit wait in selenium webdriver?

When to use explicit wait vs implicit wait in Selenium Webdriver?

On SeleniumHq also:

Implicit Waits

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

But not clear what kind of wait is this, I mean would it wait till isDispalyed, isVisible or isClickable

Community
  • 1
  • 1
paul
  • 4,333
  • 16
  • 71
  • 144

2 Answers2

1

I believe the implicit wait does not care about any of those properties (isDisplayed, isVisible or isClickable). It just waits the time you set up and checks regularly whether the element you try to select is available in your DOM. If it is not found it will lauch a timeout error.

narko
  • 3,645
  • 1
  • 28
  • 33
  • what do you mean by available? You can see it, click it or hover?? – paul Sep 17 '15 at 13:33
  • By available I mean that you can find the element in the DOM. I am referring to the code. The fact of not being visible on the screen does not mean that the element is not present in your DOM. – narko Sep 17 '15 at 13:36
  • you mean using `.findElement(By.___)`. I think you should quote an example to justify your answer. Just saying won't help anyone here. – paul Sep 17 '15 at 13:38
  • What I mean is that if you search for a button for example, the HTML code that defines this button must exist in your DOM. Then you will be able to find it using `findElement`. – narko Sep 17 '15 at 13:41
  • WebSite's logout option which can be clicked only when you hover on profile image. Now this logout was always present in DOM, but before hover it was hidden and after hover it is clickable i.e. `findElement` fails it before hover. So I think only saying "available" wont help. – paul Sep 17 '15 at 13:46
  • Ok, I think I get your point now. Correct me if I am wrong, but are you using some javascript code to control that behavior that you are referring to here: "WebSite's logout option which can be clicked only when you hover on profile image"? I can just tell you that if you are generating that logout button dynamically from your javascript code, then there is no way that Selenium will find the element until you execute the javascript somehow. Did you try clicking with Selenium on the profile image first and then trying to select your logout button? – narko Sep 17 '15 at 13:56
0

I believe narko is right and here's some code that I think proves it.

By hiddenLocator = By.id("csi");
FirefoxDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.google.com");
WebElement hiddenEle = driver.findElement(hiddenLocator);
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(hiddenLocator));
System.out.println("done");

I went to google.com and found an element that was hidden

<textarea name="csi" id="csi" style="display:none"></textarea>

I set the implicit wait to 30s, set up a WebDriverWait for 30s, and then waited for the element to be present. From the presenceOfElementLocated() source

An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible.

If implicit wait was waiting for anything other than just the presence of the element in the DOM, it would have waited for 30s... but it finished as soon as the page was loaded in the browser.

I did some research to better understand what these different functions are doing and how they are truly different. Here's what I found...

WebElement has three methods related to this question: isDisplayed(), isEnabled(), and isSelected(). From the docs...

isDisplayed() Is this element displayed or not? This method avoids the problem of having to parse an element's "style" attribute.

isEnabled() Is the element currently enabled or not? This will generally return true for everything but disabled input elements.

isSelected() Determine whether or not this element is selected or not.

ExpectedConditions also comes into play here with several methods. I'll just look briefly at elementToBeClickable(). From the docs...

elementToBeClickable An expectation for checking an element is visible and enabled such that you can click it.

If you look at the source, the description is accurate. You can look at the source for the other methods, etc. if you want more info but I think this is enough to answer your question.

JeffC
  • 22,180
  • 5
  • 32
  • 55