Appium v​​1.17.1 无法在iOS中切换WebView上下文 [英] Appium v1.17.1 unable to switch WebView context in iOS

查看:31
本文介绍了Appium v​​1.17.1 无法在iOS中切换WebView上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Previous version (1.15.1) I was able to perform this code.

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)后,就遇到了这个错误.

However after updated to the latest version (1.17.1), it encountered this error.

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

推荐答案

您使用的语法有误.

这是针对 Python 的:

This is for Python:

如果你知道上下文:

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

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

Return all available context in list:

driver.contexts

所以你可以这样使用:

driver.switch_to.context([0])

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

NOTE: web_view is always the last key in list, so you can always change the context to webview (FireFox,Chorme,Safari) with this:

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

返回当前上下文:

driver.context

这篇关于Appium v​​1.17.1 无法在iOS中切换WebView上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆