How to Identify WebView Elements in Android Hybrid App?

You can watch this video : https://youtu.be/SoHfgl9A8tI

same here I am facing please find the logs below :-1:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: unknown error: Chrome version must be >= 55.0.2883.0
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3.42 seconds
Build info: version: ‘unknown’, revision: ‘unknown’, time: ‘unknown’
System info: host: ‘PC80688’, ip: ‘10.12.131.129’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_131’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.nagra.ion, deviceScreenSize=1920x1080, networkConnectionEnabled=true, broswer_Name=Chrome, warnings={}, databaseEnabled=false, deviceName=10.12.131.30:5555, platform=LINUX, deviceUDID=10.12.131.30:5555, appActivity=MainActivity, desired={appPackage=com.nagra.ion, appActivity=MainActivity, broswer_Name=Chrome, newCommandTimeout=5000, platformVersion=5.1.1, platformName=Android, deviceName=Android}, newCommandTimeout=5000, platformVersion=5.1.1, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, javascriptEnabled=true, deviceModel=AFTS, platformName=Android, deviceManufacturer=Amazon}]
Session ID: d58ca876-a1de-4825-b234-006d932a606f
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:338)
at amazonFireTv.StartApplication.test(StartApplication.java:73)
at amazonFireTv.StartApplication.main(StartApplication.java:220)

@willosser @Free_Automation @manikanta @bhaskar @Kavi @sreetester @Sree_A @ravikr42

I am able to get context but after that I am facing issue:-1:

[MJSONWP] Encountered internal error running command: Error: unknown error: Chrome version must be >= 55.0.2883.0
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 10.0.14393 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-chromedriver\lib\chromedriver.js:176:15)
at tryCatch (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session/d58ca876-a1de-4825-b234-006d932a606f/context 500 3402 ms - 347

[MJSONWP] Encountered internal error running command: Error: unknown error: Chrome version must be >= 55.0.2883.0
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 10.0.14393 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-chromedriver\lib\chromedriver.js:176:15)
at tryCatch (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session/d58ca876-a1de-4825-b234-006d932a606f/context 500 3402 ms - 347

hello
see the appium logs:

[MJSONWP] Encountered internal error running command: Error: unknown error: Chrome version must be >= 55.0.2883.0
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 10.0.14393 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-chromedriver\lib\chromedriver.js:176:15)
at tryCatch (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (C:\Users\wanole\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session/d58ca876-a1de-4825-b234-006d932a606f/context 500 3402 ms - 347

@bhaskar I need help

Sorry, @Balaji_Wanole, I have yet to dabble with webviews.

@Balaji_Wanole

Can you let me know the scenario which you are trying to automate. and how you are doing it. Logs are fine but share more details about your scenario.

Thanks
Ravi

I have android Amazon’s firetv box.
when I was trying to switch to web view with latest appium 1.6.5. using following code.

Set availableContexts = driver.getContextHandles();
System.out.println("Total No of Context Found After we reach to WebView = "+ availableContexts.size());
for(String context : availableContexts) {
System.out.println(“context name:”+context);
if(context.contains(“WEBVIEW”)){
System.out.println("Context Name is " + context);
// 4.3 Call context() method with the id of the context you want to access and change it to WEBVIEW_1
//(This puts Appium session into a mode where all commands are interpreted as being intended for automating the web view)
driver.context(context);
break;
}
}

it is showing above error what I mentioned in my support.

but now @ravikr42 ,I tried with older version of appium .
It was working but not always 1/10 times so I am in confusion now.

One more doubt @ravikr42 can we really automate hybrid app without any drawbacks as with older versions only its working?

Try to switch context. And take page source

1 Like

Download a chrome on the PC side, then install a plugin, “ADT Pulgin”, install a chrome on the phone, and then you can locate the element.

Thanks for sharing details.
Let me try this and I will update you after.

@Balaji_Wanole

I tried Automating the app, but I am unable to switch to webview but thats fine because I am using production build. Generally in production android apps webview debugging mode is set to false. However if you have test build for the app, you will be able to see the different contexts and able to switch it.

For getting WebView Elements locator you have to use chrome remote debugger instead of UIAutomator, as UIAutomator will work for finding elements of Only Native View.

How to use chrome debugger you can find at this link.

Also , I have tried same code with different version of appium server (1.4.X, 1.5.X, 1.6.X) and its working fine for each version of the appium server.

Try this and let me know if you still face any issue.

Thanks
Ravi

1 Like

HI @JAYESH_BHOR,
you have mentioned to try Switch context and page source, it would be helpful if you detail me more on this. me working on android app in which i’m being blocked in “android.webkit.WebView”.
in android_driver.getContext() i get as “NATIVE_APP”
in android_driver.getPageSource() i get as below,

<?xml version="1.0" encoding="UTF-8"?>

i don’t know how to implement switch context (is a String right)

This helped solve my problem, thanks a lot, turned out I needed a debug apk to test on because the property was enabled in debug apk, and the tests are running now in hybrid app.
BTW I used info from this page:
http://appium.io/docs/en/writing-running-appium/web/hybrid/
to set the autoWebview.