How to Identify WebView Elements in Android Hybrid App?

I am using linux RH. What solution would you advise for me?

LaurynasKac,

Changing O/S does not change appium code it work same way,
If you are handling webview in windows,mac,linux it code remains same.
Only way to configure android sdk,running appium server will change.App under test will remains same
So same ans for u this platform also for Linux…

get app webview debugger enabled and get app built to support 4.4+,API level>18 then u can easily detect webview using

driver.getContext(); it will return Native,Webview both context
Chrome remote debugger will also show webview elements to spy upon

Hi amitjaincoer191,
Does it practicable to use Chrome remote debugger to show webview elements inside android device?
Like Uiautomator. In other words, we want to complete this work in an android jar.
The app under test has webview debugger enabled and built to support 4.4+,API level>18
Thank you very much!

Check whether WEBVIEW is enabled by developers or not, If it is not enabled you wont be able to Switch it.
The Workaround is first you have to instrument the .apk file, then it will work.

can you tell me how to instrument the .apk file?

See Appium only show native app context, is does not recognises the webview context for android app

Did you try enabling “Enable view attribute inspection” in “Developer Options” on Android device.
If it still doesn’t work once disable and enable this option and then try.
Lemme know if it works… :slight_smile:

2 Likes

@Raveendar_Reddy
I too have similar problem, already developer had enalbed flag, and i tried “Enable view attribute inspection”
It doesn’t work, even after disable and enable this option

I am facing the same issue. Even after trying by enabling “Enable view attribution inspection”. It doesn’t work. I tried to capture the screen which has two fragments inside a view pager and when try to capture the screen it shows the following error “Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn’t exist!
Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn’t exist!” . Even tried with Chrome Inspect devices option it doesnt work since it has two fragments with the same id’s.

It is working on Some devices only. I can able to identify on OnePlus2 device.On Emulators it is not working as expected.

When I started working on a Webview, i was trying to find Element by using “UIAutomerviewer” but, Realized it doesn’t work.

Later i realised using “Remote debugging tool in chrome” is the best way to do it.

I have done a video Which helps you to find Element on Webview.
https://youtu.be/oH_6KYt58Z8.

When writing code on webview, it should be little different. You have to get into Webview by using .getHandles().

Add the below piece of code at the Begining of your test

WebDriverWait wait=new WebDriverWait(driver, 10);
Set contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains(“WEBVIEW”)){
driver.context(contextName);
}
}

2 Likes

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.