1

I am trying to find an element in my page. That element will only come if there is any error in the application. I handled that pretty well, only issue is that it waits for 30 secs (Implicit wait) to move to next step. I don't want to wait for 30 secs instead I'll like my script to wait for 3 secs before moving to next step, so I decided to use explicit wait for the same. Here is my code

WebDriverWait wait = new WebDriverWait(driver, 3);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("errorelement")));

Problem is that the Selenium webdriver is still waiting for that element upto 30 secs before giving an error and moving to next step. I tried with visibilityOfElementLocated option as well but it's still not working.

Am I missing something here ?

Selenium version:- 2.46.0

Browser :- Mozilla, Chrome

Naseem
  • 911
  • 5
  • 18
  • 48
  • Could you share the full code with us? It seems that you forget to delete the 30 sec wait from somewhere. – peetya Jul 20 '15 at 06:53

3 Answers3

4

I'd recommend to set implicit wait to 0, and always use explicit wait:

driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);

Here is a good answer on this topic.

Kirill
  • 1,530
  • 5
  • 24
  • 48
2

If you are using implicit waits and explicit waits in the same solution you will have issues from the seleniumhq docs

WARNING: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10s and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.


Adding official documentation link and it's screenshot -

Please see official Selenium Documentation on mixing Explicit and Implicit waits.

(https://www.selenium.dev/documentation/en/webdriver/waits/)

enter image description here

Vikas Piprade
  • 272
  • 2
  • 7
Andy Smith
  • 56
  • 5
1

Could you share the full code with us? It seems that you forget to delete the 30 sec wait from somewhere. – peetya

This was super straight to the point, I had the same issue but it was just because I declared implicit wait for 30 seconds when launching the browser, didn't think to look back at it because it seemed "trivial". Thanks so much for pointing this out peetya.

LeechCoder
  • 11
  • 2