Explicit wait
There are times when the app under test can be slow on certain specific elements, such as page submit, form submit, or somewhere it fetches data from an external system and takes a little more time to load. In that case, using implicit wait to handle the situation will be a flawed approach, given that it has to wait for each and every element for the same specified time.
To handle this situation, we can use explicit wait for such elements. In explicit wait, we tell the web driver instance to wait for a certain condition invoked through ExpectedConditions
. So, this wait applies explicitly to the specified element. Explicit wait can be invoked using this code:
WebDriverWait wait = new WebDriverWait(appiumDriver, 10); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("text1")));
In the preceding code, we are creating an instance of WebDriverWait
with a maximum waiting time of 10 seconds and then using an ExpectedConditions
, which tells the driver to wait till the visibility...