简体   繁体   中英

APPIUM ANDROID Hybrid App: Not able to get driver context as 'WEBVIEW' when navigating to the web view from native in Hybrid app

I need to automate web view in Hybrid app. Native part automation is going fine. After clicking on one of the buttons in the native view, the app is further navigated to the Chrome browser and opens the web view. Now, the problem is that I am not able to get 'WEBVIEW' in the String Set using the driver.getContextHandles(). I only get value as 'NATIVEAPP' even after navigating to the webview. Kindly let me know where I am going wrong or there's any other approach for the same.

Tried the driver.getContextHandles() to get all contexts and then ran 'for loop' to set the driver to WEBVIEW context to perform the further actions on webview.

    //Below code is after clicking on the button on native view which 
    //navigate to the web view in the chrome browser
    Set<String> contextNames = driver.getContextHandles();
    System.out.println(contextNames);
    for (String conName : contextNames) {
    System.out.println(conName);
    if (conName.contains("WEBVIEW"))
            {
    driver.context(conName);
    }
    }

    //clicking action in the webview in browser
    driver.findElement(By.xpath(XYZ)).click();

I expect driver.getContextHandles() value as: NATIVEAPP,WEBVIEW. But I only get NATIVEAPP as output.

In order for you to be able to do any type of debugging of webview inside apps. The need to enable the web view debugging option through this key being added to the app's config: setWebContentsDebuggingEnabled and setting it's value to true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM