0

Appium server: 1.7.2 Appium-Python-Client==0.26 ios: 11.2

Using the following I would expect to find two views, native and a webview. The native view is always returned but 9/10 times it fails to return the webview context.

    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()

Because the only finds the native context it obviously then fails with the following error ---

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
Eric
  • 159
  • 2
  • 11
  • Have you tried doing this directly? self.driver.switch_to.context('WEBVIEW') ?? – barbudito Jan 23 '18 at 14:54
  • And second, are you sure this locator is actually working? find_element_by_xpath('/html/body/p[2]/a') – barbudito Jan 23 '18 at 14:55
  • Unfortunately each time it does find the webview, it has a different name such as Webview 123 to Webview 234. And it never actually gets to that point where that locator could fail. It fails when it tries to switch to webview (contexts[1]) because the list is only 1 item long (the native view). – Eric Jan 23 '18 at 15:37
  • It is 100% necessary to change to webview context? Can't achieve in native context? – barbudito Jan 24 '18 at 10:24
  • Yes it seems to necessary to switch to the webview context. It is unable to find the link element we need to click in the native webview. In one of the few times it was able to successfully find the webview to switch to, it finds the element correctly. – Eric Jan 24 '18 at 19:32

0 Answers0