【问题标题】:Appium v1.17.1 unable to switch WebView context in iOSAppium v​​1.17.1 无法在 iOS 中切换 WebView 上下文
【发布时间】:2020-06-02 09:29:00
【问题描述】:

以前的版本 (1.15.1) 我能够执行此代码。

Set<String> contextNames = driver.getContextHandles();
    for (String contextName : contextNames) {
        System.out.println(contextName); //prints out something like NATIVE_APP \n WEBVIEW_1
    }
driver.context((String) contextNames.toArray()[1]); // set context to WEBVIEW_1

但是更新到最新版本(1.17.1)后,遇到了这个错误。

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at com.sapphire.appclient.automation.page.AbstractPage.getContext(AbstractPage.java:53)
...
...

【问题讨论】:

    标签: selenium appium


    【解决方案1】:

    你使用的语法是错误的。

    这是给 Python 的:

    如果你知道上下文:

    driver.switch_to.context['NATIVE_APP]   #appium chrome driver
    driver.switch_to.context['WEB_VIEW_chrome]    # selenium chrome driver
    

    返回列表中所有可用的上下文:

    driver.contexts
    

    所以你可以这样使用:

    driver.switch_to.context([0])
    

    注意:web_view 始终是列表中的最后一个键,因此您可以随时将上下文更改为 webview(FireFox、Chorme、Safari):

    contexts = driver.contexts
    driver.switch_to.contexts[-1]
    

    返回当前上下文:

    driver.context
    

    【讨论】:

      猜你喜欢
      • 2017-07-19
      • 2020-07-14
      • 2015-09-24
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      • 2016-10-20
      相关资源
      最近更新 更多