Implicit & Explicit wait is not reliable to find the element

Hi,

I am running the appium test for hybrid app on iOS. I am using the wait condition until the element is clickable.But sometime it is not working.It is saying
“Timed out after 30 seconds waiting for element to be clickable”. It is not reliable .I am using the below code.Is there any alternate way to wait for the element.?

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); //Implicit wait
WebDriverWait wait = new WebDriverWait(driver, 30);

element = driver.findElement(By.xpath("//UIATextField[@value=‘Email address’]"));
wait.until(ExpectedConditions.elementToBeClickable(element)).click();
Thread.sleep(2000);

implicit and explicit waits don’t work well together. I recommend setting the implicit wait to 0 and exclusively using explicit waits.

FluentWait will be useful in this case? If it is useful can you tell me how to use that in my scenario?

Meanwhile i will try setting implicit wait to 0 and let you know.

@rajesh_madaswamy what @bootstraponline has replied will work for you and for your case explicitywait will work fine.
fluent and explicitly wait both wait for specific elements conditions with few basic differences, e.g in fluent wait you can specify frequency with which it can check for the condition and in explicit frequency is predefined to 500ms. And in addition to this fluent wait have few more option you can set such as specific types of exception handling.

I have set only explicit wait for 30 secs and implicit wait for 0 secs.But issue is , before loading the page (or view) only Appium trying to find the element and its retuning ,element could not be located in this page.If i set implicit wait for 60 secs,it is working fine.But some times not.

Hi . refer this tutorial to work with implicit and explicit wait with Appium

1 Like

I have the same issue! Explicit wait doesn’t work at all with Android N and Appium server 1.6.3
is it an issue?

I have the same issue on iOS real device. Appium doesn’t update the the command to get pageSource if the new screen is available. How to resolve this issue? My scripts are getting inefficient.

@sdymj84 @apcanada I’m using Explicit wait with latest Java client and appium server version, it does work properly.

You can put as little implicit wait and individual element level explicit wait.

Please go through all the comments in https://github.com/appium/java-client/issues/574

If it’s not working for you open new ticket with all the details as per issue template

Thanks,
Vikram

to solve this issue i recommend using two checks. The first is an implicitWait until this element is displayed. Then introduce an arbitrary 2000 or 5000ms sleep before initiating a click() command.

This was useful to me in cases where an element had loaded, but surrounding elements were still being shifted around for a second or two after.

for example, C#

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
bool b = false;
while (!b)
{
try{b = driver.FindElementById("grid_item_text").Displayed;}
catch{ Thread.Sleep(250); }
}

Thread.Sleep(2000);
driver.FindElementById("grid_item_text").Click();
1 Like

you have to understand the order of working implicit and explicit wait. When you have given explicit wait condition for any element to find then it waits only the time you specified in explicit wait, it wont considered the implicit wait condition.

Use explicit wait only when you feel your element load much later than the specified implicit wait time, mean keep explicit wait more than 60 second which is u mentiond in your implicit wait.

will it work for Android driver using hybrid apps

Appium designed to work with all 3 types of mobile applications, Native, Hybrid and WebApps

Could you please provide with the code snippet for it I was automating mobile application using Android driver class

It worked with latest jars:

Appium 1.7.1
Java-client 5.0.4
Selenium-java 3.7.1