Implicitly wait

Implicitly wait is used to wait upto given specific time before throwing an error as NoSuchElementException if it doesn't identify the MobileElement.

This method should be called only once per session as it is applied globally and we need to pass integer value in seconds.

Syntax :

driver.implicitly_wait(10)

If you declare ImplicitlyWait with a time of 10 seconds , if MobileElement is not visible then it waits for 10 seconds before it throws an error.

Example: In the below example we are launching the app on an Android device and waiting for an element for 15 seconds to perform action on it.

  • Launch the App on an Android device.
  • Create a implicit wait for 15 seconds
  • Using id locator wait for the element
  • As the element is not identified for 15 seconds, it throws an error after 15 seconds.

ImplicitWaitEx.py

from appium import webdriver
import time
from appium.webdriver.common.appiumby import AppiumBy

# Step 1 : Create "Desired Capabilities"
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['automationName'] = 'UiAutomator2'
desired_caps['platformVersion'] = '10'
desired_caps['deviceName'] = 'Pixel3XL'
desired_caps['app'] = ('/Skill2Lead/Appium_Demo_App/Android/Android_Appium_Demo.apk')
desired_caps['appPackage'] = 'com.skill2lead.appiumdemo'
desired_caps['appActivity'] = 'com.skill2lead.appiumdemo.MainActivity'

# Step 2 : Create "Driver object"
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

# Step 3 : Create a implicitly wait
driver.implicitly_wait(15)

# Step 4 : "Click on the button using ID locator value"
ele_id = driver.find_element(AppiumBy.ID,"com.skill2lead.appiumdemo:id/EnterValue")
ele_id.click()

# Step 5 : Wait for 2 seconds
time.sleep(2)

# Step 6 : Close the driver object
driver.quit()