2

Obviously, I can set the wait time. Is there a way to find out what the implicit wait time is set to in selenium? (C# specifically)

(The idea is to disable the ImplicitWait, do something, then reset it to whatever the time was before.)

Machtyn
  • 2,982
  • 6
  • 38
  • 64
  • There doesn't seem to be an API endpoint within Selenium for *getting* it's value, but only *setting* it's value. Your best bet is to store it's value in a local variable beforehand. – Arran Sep 16 '14 at 21:49
  • Or choose your own default values as constants and set them when initializing selenium. – SimpleVar Sep 16 '14 at 22:34

4 Answers4

0

As in docs (http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp) :

"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."

German Petrov
  • 1,475
  • 1
  • 17
  • 21
  • 1
    This doesn't answer his question. The default setting might be 0 but he is manipulating it throughout his tests with, potentially, different values. He needs to keep track of those values. – Arran Sep 17 '14 at 07:12
  • isn't this: "Once set, the implicit wait is set for the life of the WebDriver object instance." the answer for the question? – German Petrov Sep 17 '14 at 07:19
  • Why would it be? Whenever set, it's set for the life of the instance. Doesn't stop me then setting it to another value which is then for the life of the instance. – Arran Sep 17 '14 at 07:25
  • "Once set" means that the person who set knows the value, he can operate with it. If he didn set, he knows now that value was|is zero. – German Petrov Sep 17 '14 at 07:41
  • If we're using the object oriented programming model, knowing what some other method may have set the value is immaterial and potentially changing. Instead of forcing the caller of a method to provide the implicit wait time, I want to be able to discover it, to know the value as it is, not as the caller expects it to be. – Machtyn Sep 17 '14 at 13:03
0

If you use the Page Objects pattern, keep the implicitlywait time in a field of the PageBase class, additionally, you would like to create some methods to reset or retrieve that value.

Sorry that the following example is in Java:

class PageBase { 
    private WebDriver driver;
    private long implicitlyWaitTimeInSeconds;
    public PageBase(WebDriver driver, long timeout) {       
        driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
        implicitlyWaitTimeInSeconds = timeout;
        this.driver = driver;
    }
    public void setImplicitlyWaitTime(long timeout) {
        driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
        implicitlyWaitTimeInSeconds = timeout;
    }
    public long getImplicitlyWaitTime() {
        return implicitlyWaitTimeInSeconds;
    }
    ...
}

class HomePage extends PageBase {
    ...
}
user2432405
  • 1,406
  • 2
  • 14
  • 29
0

This can print real timeout value (plus calculating time, usually within 100ms) in Java but the idea is clear:

public void getCurrentWaitTimeout() {
    long milliseconds = java.time.ZonedDateTime.now().toInstant().toEpochMilli();
    driver.findElements(By.cssSelector(".nonExistingElement"));
    milliseconds = java.time.ZonedDateTime.now().toInstant().toEpochMilli() - milliseconds;
    log.info("Current waiting timeout is {} milliseconds", milliseconds);
}

So you can always call such a method to be sure you know actual timeout, not the value you tried to set.

Dima
  • 1
  • 1
0

you may find useful my answer here. In a nutshell, the method you may find useful is

WebDriver.manage().timeouts().getImplicitWaitTimeout()
Andrew
  • 2,148
  • 5
  • 23
  • 34