Time for action – using implicit waits - Selenium

In this section we will see how we can use implicit waits in our code. We need to change a number of calls together to set the implicit. This was done to keep the API as succinct as possible:

  1. Open your Java IDE. Intellij or Eclipse are the most used.

  2. We are going to use the command:

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.findElement(By.xpath("//div[@id='ajaxdiv']")
  3. Run your tests:

What just happened?

We have just seen that our tests run and pass. We didn't have to do anything special for waiting for the new text to appear on the page. Let's go see how we can do this with the explicit waiting approach.

Explicit waits

Unfortunately implicit waits do not fit all situations and for some developers is not the right thing to do. Explicit waits is when we know what we want to happen and the error needs to fit that situation.

Let's see this in action!


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics