问题描述
他们是一个依赖第三方的支付网关,现在在Web视图中打开了付款详细信息。因此,如何在本机应用程序中管理Web视图和切换上下文。请帮忙!
解决方法
您可以尝试一下。它将起作用。
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName); //prints out something like NATIVE_APP \n WEBVIEW_1
}
driver.context(contextNames.toArray()[1]); // set context to WEBVIEW_1
//do some web testing
String myText = driver.findElement(By.cssSelector(".green_button")).click();
driver.context("NATIVE_APP");
// do more native testing if we want
driver.quit();
参考:https://appium.io/docs/en/writing-running-appium/web/hybrid/