helmy
helmy

Reputation: 21

Appium v1.17.1 unable to switch WebView context in iOS

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

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

Upvotes: 0

Views: 1286

Answers (1)

Mohammad Monfared
Mohammad Monfared

Reputation: 675

The syntax you are using is wrong.

This is for Python:

If you know the context:

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

So you can use this like:

driver.switch_to.context([0])

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]

Return the current context:

driver.context

Upvotes: 1

Related Questions