>问题
我在真实设备上使用应用程序进行安卓自动化。我切换到WebView使用driver.context("webview_com.xxx.myapp"(,然后我执行driver.getPageSource((,并出现一个问题,它返回如下
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><iframe name="chromedriver dummy frame" src="about:blank"></iframe></body></html>
环境
appium:1.15.1
OS:Windows 10
API :java
Android:8.1
详
我想要的能力如下
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "b307aa10");
capabilities.setCapability("automationName", "appium");
capabilities.setCapability("platformVersion", "8.1.0");
capabilities.setCapability("appPackage", "com.dayizhihui.dayishi.hpv");
capabilities.setCapability("appActivity", ".main.view.WelcomeActivity");
capabilities.setCapability("noReset", "true");
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("androidPackage", "com.android.chrome");
capabilities.setCapability(ChromeOptions.CAPABILITY,chromeOptions);
我的代码如下
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
introducePageHandle.clickIntroduceIcon();
System.out.println("Before " + driver.getContext());
System.out.println("All Contexts " + driver.getContextHandles());
driver.context("WEBVIEW_com.dayizhihui.dayishi.hpv");
System.out.println("After " + driver.getContext());
System.out.println("PageSource " + driver.getPageSource());
起诉结果
Before NATIVE_APP
All Contexts [NATIVE_APP, WEBVIEW_com.dayizhihui.dayishi.hpv, WEBVIEW_chrome]
After WEBVIEW_com.dayizhihui.dayishi.hpv
PageSource <html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><iframe name="chromedriver dummy frame" src="about:blank"></iframe></body></html>
我真的很想有人可以帮助我解决它,谢谢高级!
铬检查
应用程序H5
图片切换到 Web 视图后,您需要切换到iframe
,因为您尝试与之交互的 Web 视图上存在 iframe。
您可以切换到 iframe,如下所示:
driver.switchTo().frame(driver.findElement(By.name("chromedriver dummy frame")));
使用autoWebview
设置功能:
capabilities.setCapability("autoWebview", true);
文档