Create is wrapper class which will wait till the element is display.
For example:
public void waitForElementToBeVisible(AndroidDriver driver,
WebElement parent, String locator[], int iteraionTimeoutInSecs,
int timeOutInSecs,boolean isThrown) throws Exception {
String elementName = (locator[0]).trim();
String elementType = (locator[1]).trim();
String elementValue = (locator[2]).trim();
String elementDescription = (locator[3]).trim();
boolean flag = false;
int count = 0;
while (flag == false) {
Thread.sleep(iteraionTimeoutInSecs * 1000);
try {
// WebElement element = getWebElement(driver,null, locator);
if (isDisplayed(driver, null, locator) == false) {
// while(!driver.findElement(By.id(elementID)).isDisplayed())
logAndroidDriverAPI.info("Waiting for an element \""
+ elementName +" ["+elementValue
+ "] \" to be displayed",true);
count = count + iteraionTimeoutInSecs;
if (count >= timeOutInSecs) {
logAndroidDriverAPI.info("Element with name \""
+ elementName + "\" value \"" + elementValue
+ "\" is not displayed after timeout "
+ timeOutInSecs,true);
// ErrorUtil.addVerificationFailure(new
// uiElementException("Timeout exception occoured while finding the UI element "+elementName
// +" elementIdentifier " +elementIdentifier));
break;
}
} else {
flag = true;
}
} catch (Exception e) {
logAndroidDriverAPI.error("Waiting for an element \""
+ elementName + "\" to be displayed with an exception");
count = count + iteraionTimeoutInSecs;
if (count >= timeOutInSecs) {
logAndroidDriverAPI.error("Element with name \""
+ elementName + "\" value \"" + elementValue
+ "\" is not displayed after timeout "
+ timeOutInSecs,true);
logAndroidDriverAPI.error(genCodes.getExceptionMessage(e));
if (isThrown){
throw e;
}else{
break;
}
//throw new AppiumServerException(e,locator);
}
}
}
}