方法一:

Set<String>contexts=driver.getContextHandles();
driver.context((String)contexts.toArray()[1]);  //选取webview开头的context

方法二(官方示例):

driver.getContextHandles().forEach((handle) -> {
                if (handle.contains("WEBVIEW")) {
                    driver.context(handle);
                }
            });

此外,好多chromdriver不兼容,我再上传一个chromdriver--云盘链接如下:

https://pan.baidu.com/s/1dFRTgRZ

 方法三:

public void context_to_webview(AppiumDriver<MobileElement> mdriver) {
        Set<String> ContextHandles = mdriver.getContextHandles();
        LOGGER.info("All ContextHandles :" + ContextHandles);
        if (ContextHandles.size() == 1) {
            LOGGER.info("该web页未开启debug状态");
        } else {
            mdriver.getContextHandles().forEach((handle) -> {
                if (handle.contains("WEBVIEW")) {
                    mdriver.context(handle);
                }
            });

        }
    }

 

原文链接:https://testerhome.com/topics/10951

相关文章:

  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-01
  • 2021-06-09
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案