Cannot find Elements in a webview using UiAutomator2 but the same elements are found with Appium(default)

Hi,
I have an issue with UiAutomator2, I cannot use this one to find elements on a web view. The same elements are found with Appium which is by default UiAutomator1 (if I’m not wrong). I tried on different API versions but I got the same results.
Every time when I’m using Uiatomator2 I got “Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.id: buttonSubmitLogin”
Do you have any idea what I can do in this case?

I am using Appium desktop v1.8.1
Appium v is 6.0.0

Here are the Capabilities :

public DesiredCapabilities HuaweiP20Lite() {
DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability(“deviceName”, “WCY4C18602004318”);
capabilities.setCapability(CapabilityType.BROWSER_NAME, “Android”);
capabilities.setCapability(CapabilityType.VERSION, “8.0”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“appPackage”, “com.lego.common.legolife.live.nightly”);
capabilities.setCapability(“appActivity”, “com.lego.common.legolife.ui.interfaces.LauncherActivity”);
capabilities.setCapability(“automationName”, “UiAutomator2”);
capabilities.setCapability(“newTimeoutCommand”, “300”);
capabilities.setCapability(“noReset”,true);
return capabilities;
}

I attached 2 logs, one is with log with UiAutomator2 and the other one is with Appium.

Appium.txt (44.1 KB)
UiAutomator2.txt (36.5 KB)

I am seeing same issue but not for webview, am using native app and still uiautomator2 unable to find elements where as uiautomator1 does it. Do you get to find the resolution?

Hi, I don’t found any solution for this case. In my case the problem was related to web views. Have you tried to update the Java client?

@Alexandru_Kispal
As per attached logs, your Android version seems to be 5.1.1
Uiautomator2 is best suited for Android 6 and above.

If, now you are using Android 6 and above try to switch to web context before accessing web element.