Unable to identify the webelement in Android6.x versions

Hello all,
I have written automation test scripts for my native app for Android platform.
I use UIAutomatorViewer to identify the elements.
The scripts are executed smoothly on Android5.x devices, But the same scripts fail to identify the elements on Android6.x .
I have tried using the following

  1. @FindBy(id =“com.husqvarna.connect:id/toolbar_title”) in my page object model pages
  2. driver.findElementById(“com.husqvarna.connect:id/toolbar_title”)
  3. driver.findElement(By.xpath("/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FramerLayout/android.view.ViewGroup[@index=‘0’]/android.widget.LinearLayout[@index=‘0’]/android.widget.FrameLayout[@index=‘0’]/android.widget.LinearLayout[@index=‘0’]/android.view.ViewGroup[@index=‘0’]/android.widget.RelativeLayout[@index=‘1’]/android.widget.TextView[@index=‘0’]")).getText();

In my 5.x devices, it easily works with the first option.

Kindly help.
Many thanks in advance.


did you try switch context to webview?

@Aleksei, how can that be done?

// java
public boolean switchToWebView() {
        for(Object context : driver.getContextHandles()) {
            System.out.println("Context Name is " + context.toString());
                return true;
        return false;

@Aleksei, Thanks for a quick response, but where is this code to be pasted?
As soon as we create the Driver instance? and is it just a one time activity?


when you open activity that have WebView you may switch contex to webview first. then try to search for your element. and do not forget return to native context once you completed in webview.

@Aleksei This did not help though, as the context is always Native.
I however figured out that, my Android SDK seems to be outdated and have to update it to have l API 23. So, do you think any thing more needs to be done on this?


@anshenoy did you enabled “setWebContentsDebuggingEnabled” for your application?
https://developer.android.com/reference/android/webkit/WebView.html ->

setWebContentsDebuggingEnabled(boolean enabled)
Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application.

how you actually realize that it is webElement?

@Aleksei, I have confirmed from the development team that they are not using any of the web components. Its all native components .

I have updated my Android SDK and the elements are now identifiable in 6.x too.