Appium-无法使用xpath定位android元素
我必须单击“允许”,才能在Android 7.0上授予应用程序权限 我尝试了以下xpathAppium-无法使用xpath定位android元素,android,xpath,appium,Android,Xpath,Appium,我必须单击“允许”,才能在Android 7.0上授予应用程序权限 我尝试了以下xpath //android.widget.Button[contains(@resource-id,'com.android.packageinstaller:id/permission_allow_button')] 还尝试了//android.widget.Button[@text='ALLOW'] 获取错误: 没有这样的元素例外 你可以试试: driver.findElement(By.id("com.a
//android.widget.Button[contains(@resource-id,'com.android.packageinstaller:id/permission_allow_button')]
还尝试了//android.widget.Button[@text='ALLOW']
获取错误:
没有这样的元素例外
你可以试试:
driver.findElement(By.id("com.android.packageinstaller:id/permission_allow_button")).click();
或
或
这对我来说很好 自,应用程序请求权限。您可以使用所需的功能直接允许权限。 试试这个:
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("autoGrantPermissions", "true");
检查首先,您需要定位警报,无论它是否存在? 因此,您可以做的是创建一个列表,该列表将检查警报是否存在?然后,如果警报存在,它将单击允许按钮 我使用的是PageObjectFactory模式,因此以下是我的代码,对我来说很好:
@AndroidFindBy(xpath = "//android.widget.Button[@text='ALLOW']")
private List<MobileElement> alert;
@AndroidFindBy(xpath = "//android.widget.Button[@text='ALLOW']")
private MobileElement allowAlert;
if (!alert.isEmpty()) {
try {
// do something
} catch (InterruptedException e) {
e.printStackTrace();
}
waitForElement(appiumDriver, allowAlert).click();
}
@AndroidFindBy(xpath=“//android.widget.Button[@text='ALLOW']”)
私人名单警报;
@AndroidFindBy(xpath=“//android.widget.Button[@text='ALLOW']”)
私人移动设备allowAlert;
如果(!alert.isEmpty()){
试一试{
//做点什么
}捕捉(中断异常e){
e、 printStackTrace();
}
waitForElement(appiumDriver,allowAlert)。单击();
}
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("autoGrantPermissions", "true");
@AndroidFindBy(xpath = "//android.widget.Button[@text='ALLOW']")
private List<MobileElement> alert;
@AndroidFindBy(xpath = "//android.widget.Button[@text='ALLOW']")
private MobileElement allowAlert;
if (!alert.isEmpty()) {
try {
// do something
} catch (InterruptedException e) {
e.printStackTrace();
}
waitForElement(appiumDriver, allowAlert).click();
}