简体   繁体   中英

Java Selenium Webdriver: Is there some form of get for implicitWait and if not why not?

I will give you a little bit of context. For most operations I am happy and the tests seem quite stable with a 4s implicit wait.

However there are moments when I know that if the element is to be displayed on the page it is there already, so if for example I'm doing operations on a list of elements I would like for the driver to not wait for 4s for every element to decide it is not there and move on.

So while I can set driver.manage().timeouts().implicitlyWait(100, TimeUnit.MILLISECONDS) and go through the list fast, I want to set the implicitWait back to its initial value when I'm done parsing the list.

Yes you can control some default settings per project and pass them around, but is not always easy when you want to do this to top projects other are depending on and setting their own defaults.

I have done a little bit of reading and everybody seems to agree that this timeout can be set multiple times per run. Selenium is quite mature now so what am I missing? Why provide a setter with no getter?

There is no such method and frankly, there is no need of it . But still if you need it for some fancy reason, you have to implement it on your own.

Lets assume you have some Base class for driver instantiation and setting common properties like wait and all. In there you can create a timeOut variable, along with its getter and setter method . And in later classes you can call getWait() wherever you want.

int timeout = 0;
    public void setWait(int timeout) {
        this.timeout = timeout;
        this.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
    }
    public int getWait() {
        return timeout;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM