Appium 1.4.16 for android doesn't recognize WEB_VIEW context

I have an android activity with webview.

However appium 1.4.16 cannot recognize this context.

How can i fix this?

myAndroidDriver.getContextHandles() ==> return list of size 1

First you need to interact with webview, then web element.
Click on `webview -> driver.findElement(By.id(“wvBase”)).click(); then you can interact with web elements.

This is how i am doing in my hybrid app automation. Hope this will work in your case as well.

Is ur app targeted to which android platform? anything below 4.4.4 will not work with appium to detect Webview… actually this is not limitation from appium side, its limitation of UIAutomator, which appium uses under the hood. So you need to run ur script under selendroid mode.

@Priyank_Shah Are you sure about 4.4.4 ? I think Appium supports above 4.2+.

Appium supports all API >=10, and if device’s API < 17 then it uses Selendroid mode, otherwise it uses android’s own UIAutomator framework. So point here, is WebView detection capability had been introduced to UIAutomator in API 4.4.4, so UIAUtomatorviewer can not detect web view if ur application’s targeted api is below 4.4.4, so Appium will not work. In such cases selendroid instrumentation will work to detect web view.

Thanks,
Priyank Shah

1 Like

Thanks

  1. So it’s not related to webView

setWebContentsDebuggingEnabled = true;

or is in addition to that flag?

  1. What does “selendroid mode” really means?
    appium not using UIAutomator? Will this affect other tests I have?

  2. I have tried this before, but the code execution fails
    when I add:

capabilities.setCapability(“automationName”, “Selendroid”);

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: hasInternetPermissionFromManifest failed. Error: Command failed: /bin/sh -c /Users/eladb/MyWorkspace/sdk/build-tools/android-4.4/aapt dump badging
ERROR: no dump file specified
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3.54 seconds
Build info: version: ‘2.47.1’, revision: ‘unknown’, time: ‘2015-07-30 11:02:44’
System info: host: ‘eladb-macbookpro.roam.corp.google.com’, ip: ‘100.105.45.192’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.11.2’, java.version: ‘1.8.0_25’
Driver info: com.waze.mobileautomation.common.android.MyAndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
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 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:141)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:37)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:160)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:168)

  1. Yes, its related to setWebContentsDebuggingEnabled = true; but that has to be done in ur code. And rebuild app by keeping target API to 19.
  2. If u switch to selendroid mode, by keeping AutomationName to Selendroid in capability. And yes it will affect your other test. because its different way of instrumentation.
  3. i think u need to stop server and try again, because aapt utility was able to resolved AndroidMenifest.xml file of ur apk.

Thanks,
Priyank Shah

  1. I did server reset, but it throws the same error.

can u try “aapt dumpsys badging ‘APK location’” from command line. I guess ur apk might get corrupted.