2

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

1
  • Could you share the full code with us? It seems that you forget to delete the 30 sec wait from somewhere. Commented Jul 20, 2015 at 6:53

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.

Comments

0

Use this syntax, it will work

WebDriverWait d = new WebDriverWait(driver, Duration.ofMillis(7000));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.