Waiting for an element to disappear

3,037 views
Skip to first unread message

Bighair

unread,
Jun 23, 2011, 4:51:27 AM6/23/11
to webdriver
Hello,

I'm pretty new to the Selenium / Java world and I've got a few tests
up and running so far, but one thing is giving me quite a bit of
trouble with WebDriver. How do I get my tests to wait for an element
to disappear?

To give a little bit of background, the web site I'm testing uses the
jQuery 'blockUI' functions to block user interaction with the page
until it has finished doing its thing. My JavaScript isn't too hot,
but I believe this places a div on the page with a class name of
'blockUI' (this simply displays a "working" message). Essentially, I
want my tests to wait for the 'blockUI' div to disappear / time out
before carrying on with the test.

Does anyone have any ideas?

Luke Inman-Semerau

unread,
Jun 23, 2011, 11:56:44 AM6/23/11
to webd...@googlegroups.com
You can use WebDriverWait (with ExpectedCondition<Boolean>) to wait until that element either doesn't exist anymore or a cssStyle like 'display' is none. I don't know how that method works, whether it hides the overlay or removes it from the dom when it is done.


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


Phil

unread,
Jun 23, 2011, 12:00:20 PM6/23/11
to webdriver
Hi Bighair,

You could probably use the selenium.isElementPresent() method (or
webdrivers FindElement() method if you're not using Selenium 2) inside
a dowhile loop to continue looping until the element is not present,
or until it has completed a certain number of iterations. And maybe
assign a boolean to be set to true if it is found so you can fail the
test afterwards if it cycles completely without the element
disappearing.

Hope this helps
Phil

Bighair

unread,
Jun 27, 2011, 5:34:54 AM6/27/11
to webdriver
Thanks Luke,

I used ExpectedCondition<Boolean> and just switched around the return
values so it returned true when the element wasn't there. It took me
a little while to get my head around the reversed conditions :0)

Bighair

unread,
Jun 27, 2011, 5:38:07 AM6/27/11
to webdriver
Thanks Phil,

I'm using WebDriver so I created an 'isElementPresent' method and used
the result of that in my WebDriverWait conditions.

Cheers,
Matt
Reply all
Reply to author
Forward
0 new messages