MobileElement followButton = (MobileElement) driver.findElement(By.xpath("//android.widget.ListView[@index='0']//android.widget.FrameLayout[@index='"+loopVal+"']//android.widget.LinearLayout[@index='0']//android.widget.FrameLayout[@index='2']//android.widget.TextView[@index='0']"));
if(driver.findElements(followButton).isEmpty()) {
//do something
}
它给了findElements我一个错误,上面写着
findElements(By) 方法不适用于参数 (MobileElement)
所以我试着把这个方法重新组织成一个 try-catch
try {
MobileElement followButton = (MobileElement) driver.findElement(By.xpath("//android.widget.ListView[@index='0']//android.widget.FrameLayout[@index='"+loopVal+"']//android.widget.LinearLayout[@index='0']//android.widget.FrameLayout[@index='2']//android.widget.TextView[@index='0']"));
} catch (org.openqa.selenium.NoSuchElementException e) {
//do something
}
.getText();但是现在的新错误是当我尝试followButton
String followOrNot = followButton.getText();
它给了我一个错误,上面写着
followButton 无法解决
基本上我要做的是找到followButton并运行.getText(),但如果followButton没有找到,执行操作来处理错误
任何人都可以帮忙吗?