Hi,
Please make sure that the version of selenium-server-standalone, selenium-java, java-client.
I used them as below:
selenium-server-standalone-2.48.2.jar
selenium-java-2.48.2.jar
java-client-3.2.0.jar
My code as below:
protected void switchToWebview() throws Exception {
// E.G.['NATIVE_APP', 'WEBVIEW_1', ...]
Set<String> contexts = driver.getContextHandles();
// make sure we have something other than the native context
// assertThat(contexts.size(), greaterThan(1));
for (String context : contexts) {
// System.out.println(contexts);
if (!context.equals("NATIVE_APP")) {
driver.context((String) contexts.toArray()[1]);
break;
}
}
System.out.println("execute context switch successfully!!! "
+ contexts.toArray()[1]);
}