一、显式等待,重写点击事件,找到该ID就点击
/**
* 显式等待,重写点击事件,找到该ID就点击
* @param driver
* @param resource ID名称
*/
public void ClickByID(AndroidDriver driver,String resource){
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id(resource))).click();
}
二、显式等待,重写点击事件,找到该xpath就点击
/**
* 显式等待,重写点击事件,找到该xpath就点击
* @param driver
* @param resource
*/
public void ClickByXpath(AndroidDriver driver,String resource){
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(resource))).click();
}
三、显式等待,重写点击事件,找到该ContentDesc就点击
/**
* 显式等待,重写点击事件,找到该ContentDesc就点击
* @param driver
* @param resource
*/
public void ClickByContentDesc(AndroidDriver driver,String resource){
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId(resource))).click();
}
四、根据xpath定位
如上截图,需要判断如果点击前言的话,前言下面会不会出现line的横线
driver.findElementByXPath("//*[@resource-id = 'net.csdn.csdnplus:id/llskill' and @index = '3']/android.widget.TextView[2]");
driver.findElementByXPath("//*[@resource-id = 'net.csdn.csdnplus:id/llskill' and @index = '3']/android.widget.TextView[contains(@resource-id,'net.csdn.csdnplus:id/line')]");