user3551863
user3551863

Reputation: 311

Selenium + Appium - ImplicitlyWait not working

I'm trying to automate some test for my Android app and ImplicitlyWait is not working.
I get the error the element doesn't exist right away. If I use explicit wait, it works fine but I don't want to explicit it all the time.

Code:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

# Output log
[BaseDriver] Waiting up to 30000 ms for condition

I'm using:

 - selenium-java: 3.13  
 - io.appium.java-client: 6.1.0

Upvotes: 0

Views: 2208

Answers (2)

Amit Jain
Amit Jain

Reputation: 4597

  1. If you want to implicitly wait for all elements to a fix time use below statement once in your BasePage class or Base/Parent class setUp method as is set for the life of the WebDriver object instance. So we write this statement only once.

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

  2. If you ever want to use explicit wait in sub class then first use this statement by override implicit wait to zero then use explicit wait.

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

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

Recommendation to read official docs here

Upvotes: 0

cruisepandey
cruisepandey

Reputation: 29362

Implicit wait means :

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.

Explicit wait :

An explicit wait is code you define to wait for a certain condition to occur before proceeding further in the code.

There are some convenience methods provided that help you write code that will wait only as long as required :

in this case code would be :

WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));  

If you are using explicit wait like this, then there is no problem. But if you are using Thread.sleep(time), then Note that it is a worst/extreme kind of Explicit wait which should be avoided as much as possible.

Hope this will help you.

Upvotes: 3

Related Questions