我已经编写了以下代码来打开应用并点击应用上的链接。但是当我调试代码时,Android应用程序意外关闭。当我尝试在调试模式下验证列表中的元素时,我看到我的应用程序在我的手机上关闭了。请在下面找到我的代码:
File classRootPath = new File(System.getProperty("user.dir"));
File appDir = new File(classRootPath, "//Apps//");
File app = new File(appDir, "base.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "XT1033");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.0.2");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "com.bt.bms");
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.bt.bms.activities.MainTabActivity");
AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(
new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(5000);
List<WebElement> elements = driver.findElements(By.id("tabText"));
System.out.println(elements.size());
System.out.println(elements.get(2).getText());
elements.get(2).click();
driver.closeApp();
}
答案 0 :(得分:1)
是的,因为它的点击速度非常快,而且您之后就有driver.closeApp();
,因此非常快。只需在click();
之后输入wait命令,它就能正常工作。