我正在使用Java使用Appium自动化Android应用程序 . 我的情况是,我需要点击按钮1或按钮2,无论哪个存在
Appium错误日志:[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug]找不到元素 . 清除辅助功能缓存并重试 . [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug]查找'//android.widget.ImageButton[@resource-id='net.ilius.android.meetic:id/profileMailPremiumButton']'使用'XPATH'和contextId :''倍数:假
if (driver.findElementByXPath("//android.widget.ImageButton[@resource-id='net.ilius.android.meetic:id/profileMailPremiumButton']")
.isDisplayed()) {
driver.findElementByXPath("//android.widget.ImageButton[@resource-id='net.ilius.android.meetic:id/profileMailPremiumButton']")
.click();
} else {
driver.findElementById("net.ilius.android.meetic:id/profileMailButton").click();
}
1 回答
如果使用 isDisplayed() ,则UI it will throw the exception - element not found 上不存在元素 .
因此,不是首先使用findElements检查该元素是否存在: driver.findElements(selector).isEmpty()
如果它是空的,则表示元素不可用,现在你可以转到else块
Use this piece of code : `