WebDriverWait timeout and implicitlyWait timeout

361 views
Skip to first unread message

Mihai Razvan-Eduard

unread,
Nov 2, 2011, 7:37:57 AM11/2/11
to seleniu...@googlegroups.com
Hello,


I'm trying to set a WebDriverWait timeout smaller than implicitlyWait timeout, but it seems that the webdriver waits the full time(i guess at least the implicitlyWait timeout but it could be both timeouts cumulated).

In this example the test does not fail after 5 seconds. When eventually the test fails it says that it failed after a 5 seconds timeout:

import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;


public class test {
   
    @Test
    public void test(){
        WebDriver driver=new FirefoxDriver();
        driver.get("http://www.google.com");
        driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
        WebDriverWait wait = new WebDriverWait(driver, 5, 1500);
        wait.until(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver d) {
                WebElement progress = d.findElement(By.name("bla bla bla"));
                return progress.isDisplayed();
            }
        });
       
    }
   

}

Now my question is : Is this a bug or a feature or am I doing something wrong?

Luke Inman-Semerau

unread,
Nov 2, 2011, 6:55:19 PM11/2/11
to seleniu...@googlegroups.com
Something wrong ;)

So what your script is doing:

setting the implicitly wait to 120 seconds.

make a request to find the element By.name("bla bla bla")

The server (because implicitly wait was set to 120) is now going to re-try to find the element for up to 120 seconds, it will return the element if found, otherwise it throws an Element not found exception. <- your case, the exception is thrown.

the wait.until method catches the ElementNotFoundException, checks to see if the time elapsed has been at least 5 seconds (which it has) and throws a TimeoutException.

Thus the WebDriverWait here is completely pointless. It only makes one request (not multiple). If you want the wait to poll many times, then you should get rid of the implicit wait... but you'll most likely hit the same error, because your element you are trying to locate doesn't exist on the page :)


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Mihai Razvan-Eduard

unread,
Nov 2, 2011, 7:15:44 PM11/2/11
to seleniu...@googlegroups.com
Uhm, well in my case I needed a way to find if something exists on a page and if it does perform one thing and if not another and I did not wanted to wait for the  implicitly wait TimeoutException so I thought that by using wait.until it would somehow override the default timeout. In any case I solved the problem by setting the implicit wait in the apply method and then resetting it to the initial value. 
Reply all
Reply to author
Forward
0 new messages