Sometimes cannot find element in WebView in hybrid app

I have a test where I am loading an Android app, which loads HTML pages (a hybrid app), then clicks some buttons and types some stuff.
The issue is it works maybe 75% of the time.

Here is the code that I am using:
driver.context(WEBVIEW_com.rest.of.the.package)
textBox =
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath(".//input[@id=“email_login”]")));
textBox.click();
textBox.clear();
textBox.sendKeys(TestData.EMAIL);
textBox.sendKeys(Keys.ENTER);

This is the element I am trying to locate:
<input type=“email” maxlength=“128” id=“email_login” placeholder=“Email” name=“email” autocorrect=“off” autocapitalize=“off”>

What I have tried:
Everything in this: https://lintaonz.wordpress.com/2011/11/24/why-seleniumwebdriver-sometimes-fail-to-find-element/
Pretty much every stackoverflow post of the same question (Just call the method again, wait longer, etc).
Getting the element by different attributes. ID, XPath, name, etc.
Using ExpectedConditions.presenceOfElementLocatedBy() as well as visibilityOfElementLocatedBy().
Doing it in native context as well

Chromedriver version: 2.43.600229
Chrome version on phone: 69
Appium version: Persists across 1.9.1 and 1.15

If anyone could help me, that would be greatly appreciated.

Thank you.

Hello

Apply sleep before element click action

I think you should try an explicit wait:

I tried that but then I remembered it’s not getting past the wait.until() line, because it can’t find the element in the first place.

Hi there, thanks for the reply. The link you sent me uses wait.until() as their example of an explicit wait. As you can see in my example code, that is exactly what I am doing.

I would increase the time you are waiting then. Make it unreasonable, like 90 seconds or something. Your tests shouldn’t take much more time, because during an explicit wait the code will return when the element is found. If you add a timer to your function you may be able to dial it back to a more reasonable number.

I suspect that your wait is something like 5 seconds and 25% of the time it is taking 7-10 seconds.

Hey there. I have tried with wait times of up to 3 minutes. It is still unable to find the elements.

Wow, so this is still happening approx 25% of the time? Is there a transition phase in the GUI that might account for this, or is the UI stable and the elements just can’t be found?

Also, can you reproduce this with Appium Desktop? Such as if you used the app and got to this screen and refreshed from Desktop and couldn’t see the elements? I’m just wondering if there is some intermittent state that could be blocking. Desktop could help to identify the state and code around it.