3

I came across a situation where I need to wait until an element disappears (in firefox). So I tried different options but nothing worked so tried using

new WebDriverWait(Drivers._driverInstance, new TimeSpan(0, 0, 2)).Until(ExpectedConditions.InvisibilityOfElementLocated(locator));

This worked but it takes 26 seconds to run the test case. When I commented that sentence it took half of the time. Why does this particular method takes more time. Though I mentioned only 2 seconds it's waiting for nearly 10 seconds. Why is it doing so? Is there a quicker way to wait until element disappears.

Thanks.

Sudeepthi
  • 494
  • 4
  • 20
  • Do you have an implicit wait in the code before this? – Grasshopper Nov 09 '16 at 16:50
  • @Grasshopper Ya I do. – Sudeepthi Nov 09 '16 at 17:08
  • 2
    Remove it and try. Mixture of implicit and explicit may be causing this behaviour. – Grasshopper Nov 09 '16 at 17:21
  • Did that work ? – Knu8 Nov 10 '16 at 08:29
  • @Grasshopper Thank you that worked. So implicit wait in a test case has it's influence through out the test case, though we wanted it only at a certain point? – Sudeepthi Nov 10 '16 at 09:23
  • 1
    @Knu8 It worked. Thank you. – Sudeepthi Nov 10 '16 at 09:23
  • 1
    @Sudeepthi Implicit waits are set once and last throughout the life of the driver instance. IMHO it's best to NOT use implicit waits but instead use explicit waits (`WebDriverWait`) when needed. Unless your page is very dynamic, you should be able to wait until the page loads by using `WebDriverWait` for a specific element. Once that element is loaded, you know that the page is loaded so you can scrape anything on the page. If you do something that triggers a page change, wait again, and then proceed. – JeffC Nov 10 '16 at 14:21
  • @Grasshopper Please post your comment as an answer so OP can accept it. Thanks! – JeffC Nov 10 '16 at 14:22
  • Added as answer – Grasshopper Nov 11 '16 at 05:27
  • @JeffC Even I avoid implicit wait too but after I updated to FF 49, explicit wait is not working as expected. So to avoid Thread.Sleep, I used implicit wait. I'm facing issue with ExpectedConditions.ElementIsVisible, though the element is present, it timeouts. It used to work with older version 47.0.1. ElementToBeClickable is also not working as expected. Don't know why. – Sudeepthi Nov 11 '16 at 10:44

1 Answers1

5

If you have an implicit wait in your code before this explicit wait. Remove the implicit wait and try. Mixture of implicit and explicit wait could be causing this behaviour.

Check this out and look at the accepted answer -- Clarification on the cause of mixing Implicit and Explicit waits of Selenium doc

Community
  • 1
  • 1
Grasshopper
  • 8,908
  • 2
  • 17
  • 32