Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Script not able to locate element on Real Device post switching to webview of a hybrid app. #243

Open
Rahul1970 opened this issue Mar 14, 2022 · 9 comments

Comments

@Rahul1970
Copy link

The problem
Unable to locate element on Real Device post switching to webview of a hybrid app.

Environment
Appium version : 1.22.2
Desktop OS/version used to run Appium: Windows 10 Android Version 10
Node.js version : v16.13.1
Npm or Yarn package manager: 8.1.2
Mobile platform/version under test: Android 10
Real device : Galaxy M20
Appium CLI or Appium.app|exe: Appium CLI

Chromedriver on Real Device used: 98.0.4758.48
Chromedriver on Emulator used: 83.0.4103.106

Links to chromedriver Logs
Chromedriver getpagesource() response logs on emulator. https://gist.github.com/Rahul1970/97f8e8fd0a5f1145873a237855ba33c1.js
Chromedriver getpagesource() response logs on real device.
https://gist.github.com/Rahul1970/bf078ac294e534b7749f5e33493bd110.js

Link to Appium logs
1..Appium logs for working code on emulator on successful switch context to webview and able to locate element.
https://gist.github.com/Rahul1970/c503aa9943cf60649a7fed269f5b5797.js
2. Appium logs on real device on successful switch context to webview but not able to locate element.
https://gist.github.com/Rahul1970/585e3c08718ec291bf2b0c4452af89b3.js

Details
In my hybrid mobile application on real device i am able to pass through the native views but when landing on webview and able to switch to webview i am not able to locate element. I am able to locate elements on webview in emulator but not able to do so on real device.

Code To Reproduce Issue [ Good To Have ]
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);//deviceName
dc.setCapability(MobileCapabilityType.UDID, deviceName );
//dc.setCapability(MobileCapabilityType.PLATFORM_VERSION,platformVersion);
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir")+"/src/test/resources/apps/"+AppName);
dc.setCapability("automationName","UiAutomator2");
dc.setCapability("unicodeKeyboard", true);
dc.setCapability("resetKeyboard", true);
dc.setCapability("autoWebview", false);
//dc.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
//dc.setCapability("appWaitForLaunch", false);
dc.setCapability("appPackage", "com.crmnextmobile.crmnextofflineplay");
dc.setCapability("appActivity", "com.crmnextmobile.crmnextofflineplay.qr.QrScannerActivity");
driver = new AndroidDriver(service.getUrl(),dc);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
ReUsableMethods.mobileStartRecording();
login();
ReUsableMethods.clickElement(sp.itemMenu," Menu Summary Page ");
ReUsableMethods.clickElement(lp.leadMenu,"Lead Menu Page");
ReUsableMethods.clickElement(lp.addLead,"Lead Add icon");
ReUsableMethods.clickElement(lp.addNewLead,"Add new lead");
Set contextNames = ((SupportsContextSwitching)driver).getContextHandles();
for (String contextName : contextNames)
{
System.out.println("Available Context"+contextName);
}
System.out.println("Before Context Switch"); ////Switching context to webview
((SupportsContextSwitching) driver).context("WEBVIEW_com.crmnextmobile.crmnextofflineplay");
System.out.println("After Context Switch");
Thread.sleep(10000);
ReUsableMethods.mobileStartRecording();
ReUsableMethods.enterText(lp.shortName,Leads[0], "shortname is entered.");
System.out.println(" Context Switched");
Thread.sleep(4000);

Hi Team Any help in this direction would be very helpful.

@jlipps
Copy link
Member

jlipps commented Mar 14, 2022

Those don't look like Appium logs

@jlipps
Copy link
Member

jlipps commented Mar 14, 2022

Your client code also appears to be using some kind of framework so it's not really possible to understand what commands are being run without seeing the Appium logs

@Rahul1970
Copy link
Author

Rahul1970 commented Mar 15, 2022

Hi Jlipps,
I have attached the appium logs for your reference in the issue description. Sharing again

Link to Appium logs
1..Appium logs for working code on emulator on successful switch context to webview and able to locate element.

<script src="https://gist.github.com/Rahul1970/c503aa9943cf60649a7fed269f5b5797.js"></script>
  1. Appium logs on real device on successful switch context to webview but not able to locate element.
<script src="https://gist.github.com/Rahul1970/585e3c08718ec291bf2b0c4452af89b3.js"></script>

Links to chromedriver Logs
Chromedriver getpagesource() response logs on emulator.

<script src="https://gist.github.com/Rahul1970/97f8e8fd0a5f1145873a237855ba33c1.js"></script>

Chromedriver getpagesource() response logs on real device.

<script src="https://gist.github.com/Rahul1970/bf078ac294e534b7749f5e33493bd110.js"></script>

Please Suggest.

@KazuCocoa
Copy link
Member

It seems like the chromedriver/chrome browser version itself could not find it.

�[35m[WD Proxy]�[39m Got response with status 404: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {"method":"xpath","selector":"//input[@data-autoid='LASTNAME_ctrl']"}\n (Session info: chrome=98.0.4758.101)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0076A0A3+2597027]\n\tOrdinal0 [0x006FBA61+2144865]\n\tOrdinal0 [0x005F3C58+1064024]\n\tOrdinal0 [0x0062020E+1245710]\n\tOrdinal0 [0x0062040B+1246219]\n\tOrdinal0 [0x0064A722+1419042]\n\tOrdinal0 [0x006387F4+1345524]\n\tOrdinal0 [0x00648B1A+1411866]\n\tOrdinal0 [0x006385C6+1344966]\n\tOrdinal0 [0x006154C6+1201350]\n\tOrdinal0 [0x006163B6+1205174]\n\tGetHandleVerifier [0x009110A2+1681842]\n\tGetHandleVerifier [0x009C3B0C+2413596]\n\tGetHandleVerifier [0x00801221+568113]\n\tGetHandleVerifier [0x007FFFA3+563379]\n\tOrdinal0 [0x0070174E+2168654]\n\tOrdinal0 [0x00706538+2188600]\n\tOrdinal0 [0x00706680+2188928]\n\tOrdinal0 [0x0071030C+2229004]\n\tBaseThreadInitThunk [0x74FDFA29+25]\n\tRtlGetAppContainerNamedObjectPath [0x77007A9E+286]\n\tRtlGetAppContainerNamedObjectP...

Chromedriver on Real Device used: 98.0.4758.48
Chromedriver on Emulator used: 83.0.4103.106

One possible reason from this comment is newer chrome/chromedriver cannot find them. If you have a device that has older chrome, you can try it out...

@Rahul1970
Copy link
Author

Hi KazuCocoa,
I have used chromedriver 83.0.4103.106 on emulator it is working fine. When i am using chromedriver 98.0.4758.48 or chromedriver 99.0.4844.73 on real device i am getting unable to locate element error.

@KazuCocoa
Copy link
Member

Yes, so I assume older chrome version and chromedriver for Android might work.
Kindly report it to Google.

@KazuCocoa
Copy link
Member

You also can create a Play Store available emulator instance and update the chrome to v98 to confirm if it is chrome/chromedriver dependent or manufacture dependent.

@Rahul1970
Copy link
Author

Hi KazuCocoa,
I am able to run my script on chromedriver 83.0.4103.106 on emulator and on chromedriver 81.0.4044.138 on real device. However when i am running it on chromedriver 99.0.4844.73 with browser version 99.0.4844.73 on real device i am getting message "Unable to locate element.". Moreover i have also tried to downgrade my chromebrowser version to 98.0.4758.101 and used chromedriver 98.0.4758.102 also tried the similar activity for
chromebrowser version to 97.0.4692.70 and used chromedriver 97.0.4692.71. But for downgraded version apk i am getting the message No chromederiver found for chrome browser version 99.0.4844.73.

(Steps used for downgrading chromebrowser version 1. Disable autoupdate 2. Uninstall updates for chromedriver 3. Install the downgrade version browser apk. 4 Install the chromedriver version matching the browser apk .)

@KazuCocoa
Copy link
Member

Perhaps the android WebView's chrome browser version was v99.

No chromederiver found for chrome browser version 99.0.4844.73.

Generally it means the app's webview process runs as chrome browser v99, and the chromedriver cannot work with it because of lower chromedriver version than the chrome version.

I am able to run my script on chromedriver 83.0.4103.106 on emulator and on chromedriver 81.0.4044.138 on real device.

Hm, it sounds like chrome/chromedriver has kind of regressions. Then, only Google can improve it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants