Appium 服务器:1.7.2 Appium-Python-Client==0.26 ios:11.2
使用以下内容,我希望找到两个视图,原生视图和 web 视图。本机视图总是返回,但 9/10 次它未能返回 webview 上下文。
contexts = self.driver.contexts
print "List of contexts " + str(contexts)
webview = contexts[1]
appview = contexts[0]
self.driver.switch_to.context(webview)
print "Switched to " + str(webview)
# Click on link in webview
self.driver.find_element_by_xpath('/html/body/p[2]/a').click()
因为唯一找到了本机上下文,所以它显然会失败并出现以下错误——
test_1_sso (__main__.SmokeTest) ... List of contexts [u'NATIVE_APP']
ERROR
======================================================================
ERROR: test_1_sso (__main__.SmokeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_sso_ios.py", line 121, in test_1_sso
webview = contexts[1]
IndexError: list index out of range