selenium - Appium v1.17.1 无法在 iOS 中切换 WebView 上下文
问题描述
以前的版本 (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)
...
...
解决方案
您使用的语法是错误的。
这是针对 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
推荐阅读
- react-native - React Native - 模块 AppRegistry 不是注册的可调用模块
- javascript - 这段有趣的 JavaScript 代码是如何工作的?
- apache - 如何使用空查询参数进行 htaccess 重定向?
- google-cloud-platform - 为什么 Google Cloud Spanner 中节点越多更新延迟越高
- javascript - 反应从另一个文件夹导入 svg 文件
- python - Spotify Python API 调用超时问题
- c++ - 打印用户选择的行
- javascript - React JS:为什么我在 componentdidMount() 处出现错误?
- angular - Angular:如何将服务中的数据绑定到组件,以便服务中的新数据更新组件?
- gremlin - 如何获取 JanusGraph Gremlin 返回的子图的邻接矩阵?