Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium get value of current implicit wait

I realize that Selenium has a default value for implicit waits, but how do I get this value if I change it? For example:

driver.implicitly_wait( 13 );

How do I later get the 13 value from the driver?

like image 927
user2426679 Avatar asked Apr 04 '14 19:04

user2426679


2 Answers

Unfortunately there's no getter for that.

http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html

There isn't for explicit waits either.

http://selenium.googlecode.com/svn/trunk/docs/api/java/com/thoughtworks/selenium/Wait.html

like image 70
JaneGoodall Avatar answered Nov 17 '22 15:11

JaneGoodall


I know I'm a couple years late, and @JaneGoodall is not wrong -- there is no built-in function for that. But it's not impossible!

It's not very difficult to create your own versions of the WebDriver interface and browser-specific driver class. And then, you can put whatever code you want into the driver!

Example:

MyDriver.java (specialized version of WebDriver, not quite mandatory but a very good idea):

public interface MyDriver extends WebDriver {
    void setWait(int timeout);
    int getWait();
}

MyChrome.java (specialized version of ChromeDriver -- works the same for any browser)

public class MyChrome extends ChromeDriver implements MyDriver {
    int timeout = 0;
    public void setWait(int timeout) {
        this.timeout = timeout;
        this.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
    }
    public int getWait() {
        return timeout;
    }
}

And now, to use it, MyProgram.java:

public class MyProgram {
    MyDriver driver = new MyChrome();
    driver.setWait(10);
    assert(driver.getWait() == 10);
}

I hope this is helpful!

like image 23
forresthopkinsa Avatar answered Nov 17 '22 17:11

forresthopkinsa