【问题标题】:Android & Appium(Java) : WebView inaccessibleAndroid & Appium(Java):WebView 无法访问
【发布时间】:2015-11-10 04:23:14
【问题描述】:

我目前正在使用 Appium,但在查找 WebView 上下文时遇到了问题。使用 UIAutomator 我可以检查 WebView 并查看其子元素,但是我无法使用 CSS 选择器/XPATH 访问其中的任何一个,因为我无法切换到 WebView。

我尝试循环遍历 driver.getContextHandles(),但这只是返回“NAVTIVE_APP”。

使用的Android 版本是5.0.1 和最新版本的Appium。

有谁知道找出 WebView 名称或可能切换到它的方法?

【问题讨论】:

  • 开发者是否开启了WebViews调试?检查他们是否在代码中调用了 setWebContentsDebuggingEnabled。
  • 我已经找到了解决这个问题的有效方法。我们没有尝试通过 Name 使用的 ID 来收集元素,而是返回了我们尝试访问的元素。谢谢。

标签: java android webview automated-tests appium


【解决方案1】:

您需要处理上下文....下面是使用 Facebook webview 处理登录的示例。它对我有用....

Set<String> contextHandles = driver.getContextHandles();
    for (String s : contextHandles) {
        System.out.println("Context : " + s);
//if context contains webview then set the webview context
        if (s.contains("WEBVIEW")) {

            //System.out.println("Set the Context NATIVE to WEBVIEW");
            driver.context(s);
        }
    }

    driver.findElement(By.xpath("//android.widget.EditText[@index='0']")).sendKeys(EMAIL);
    //System.out.println("UserName Entered");
    //sleep(3000);

    driver.findElement(By.xpath("//android.widget.EditText[@index='1']")).sendKeys(PASSWORD);
    //System.out.println("Password Entered");

【讨论】:

    猜你喜欢
    • 2019-09-16
    • 2020-01-30
    • 2017-09-26
    • 2017-04-20
    • 2016-04-19
    • 2018-03-25
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    相关资源
    最近更新 更多