ExpectedConditions.not() not behaving as expected

1,500 views
Skip to first unread message

confusa

unread,
May 9, 2013, 1:45:21 PM5/9/13
to webd...@googlegroups.com
Here is some code using WebDriverWait and ExpectedConditions to interact with an alert box. The first part waits until the alert is present and accepts no problem. Then I try to wait again for the alert to NOT be present and it seems it is still waiting for it TO be present. What am I doing wrong here?

    public void acceptConfirmation() {
    Alert alert = null;
    WebDriverWait wait = new WebDriverWait(driver, 10, 50);
    try {
        alert = wait.until(ExpectedConditions.alertIsPresent());
        alert.accept();
        wait.until(ExpectedConditions.not(ExpectedConditions.alertIsPresent()));
    } catch (TimeoutException e) {
        e.printStackTrace();
    }

    }

Error being thrown:
org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for condition to not be valid: alert to be present

Richard Lavoie

unread,
May 9, 2013, 2:27:54 PM5/9/13
to webd...@googlegroups.com
The problem is not the .not() behaving weird. It is the fact that you wait for the alert eing present then you negate te result.

Expectations.not(Expectations.alertIsPresent()) will wait for the alert to be present(.alertIsPresent())then tell you it's not(.not())

You will have to use another expectation to see if the alert is not present.
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Luke Inman-Semerau

unread,
May 9, 2013, 2:31:33 PM5/9/13
to webd...@googlegroups.com
There's a logic error in the ExpectedConditions class... I've just fixed it (I think):

https://github.com/SeleniumHQ/selenium/commit/b9487ce33e056fdf318b64806c9186a050b6a7e8




--

confusa

unread,
May 13, 2013, 12:53:01 PM5/13/13
to webd...@googlegroups.com
Awesome! Roughly how long until the fix appears in a new release build?

Luke Inman-Semerau

unread,
May 13, 2013, 1:14:09 PM5/13/13
to webd...@googlegroups.com
Likely the week after FF21 is released, which is this week, so likely next week :)

-Luke
Reply all
Reply to author
Forward
0 new messages