Java Appium能够看到屏幕上显示的内容以外的内容

Java Appium能够看到屏幕上显示的内容以外的内容,java,appium,Java,Appium,Appium能够查看和查找屏幕上未显示的元素 我正在尝试构建一个测试自动化项目,我希望我的驱动程序向下滚动 然后执行一些操作。但由于某些原因,即使不向下滚动,appium也能找到元素。我不知道appium是如何识别屏幕上不存在的元素的,当你们向下滚动时,只有肉眼才能看到。有人发现了类似问题的解决方法吗 我正在使用ExpectedCondition.visibilityOF(元素)来确定元素在屏幕上是否可见 public boolean verifyCoverage(String covera

Appium能够查看和查找屏幕上未显示的元素

我正在尝试构建一个测试自动化项目,我希望我的驱动程序向下滚动 然后执行一些操作。但由于某些原因,即使不向下滚动,appium也能找到元素。我不知道appium是如何识别屏幕上不存在的元素的,当你们向下滚动时,只有肉眼才能看到。有人发现了类似问题的解决方法吗

我正在使用ExpectedCondition.visibilityOF(元素)来确定元素在屏幕上是否可见

  public boolean verifyCoverage(String coverage, String value, String type) throws IOException, InterruptedException {
    int counter = 0;

    for (int i = 0; i < 15; i++) {
        AndroidElement element = (AndroidElement) driver.findElementByAndroidUIAutomator("UiSelector().textContains(\"" + coverage + "\")");
        //WebElement coverageOption= driver.findElementByXPath("//android.widget.Button[contains(text(),'"+coverage+"')]");
        if (AndroidUtilities.waitForVisibility(driver, element)) {

            return true;
        }
        else {
            System.out.println ("Cannot see");

            return false;
        }

    }

public static boolean waitForVisibility(AndroidDriver<WebElement> driver, AndroidElement AndroidElement){
    try{
        // driver.findElementByAndroidUIAutomator("UiSelector().resourceId(\""+targetResourceId+"\")");

        WebDriverWait wait = new WebDriverWait(driver, 60);
        wait.until(ExpectedConditions.visibilityOf(AndroidElement));
        boolean isElementPresent = AndroidElement.isDisplayed();
        return isElementPresent;    
    }catch(Exception e){
        boolean isElementPresent = false;
        System.out.println(e.getMessage());
        return isElementPresent;
    }

}
public boolean verifyCoverage(字符串覆盖率、字符串值、字符串类型)抛出IOException、InterruptedException{
int计数器=0;
对于(int i=0;i<15;i++){
AndroidElement元素=(AndroidElement)驱动程序。findElementByAndroidUIAutomator(“UiSelector().textContains(\“”+coverage+“\”);
//WebElement coverage geoption=driver.findelementbypath(“//android.widget.Button[contains(text(),“+coverage+”)]”);
if(AndroidUtilities.waitForVisibility(驱动程序,元素)){
返回true;
}
否则{
System.out.println(“看不见”);
返回false;
}
}
公共静态布尔waitForVisibility(AndroidDriver驱动程序,AndroidElement AndroidElement){
试一试{
//driver.findElementByAndroidUIAutomator(“UiSelector().resourceId(\“”+targetResourceId+“\”);
WebDriverWait wait=新的WebDriverWait(驱动程序,60);
等待,直到(AndroidElement)的预期条件可见;
布尔值isElementPresent=AndroidElement.isDisplayed();
返回isElementPresent;
}捕获(例外e){
布尔值isElementPresent=false;
System.out.println(e.getMessage());
返回isElementPresent;
}
}

作为回答,我建议您使用
visibilityOfElementLocated
而不是
visibilityOf
。 另外,如果要检查元素是否存在而不获取异常,请尝试采用这种方法:

if (!((AndroidDriver)driver).findElementsByAndroidUIAutomator("UiSelector().textContains(\"" + coverage + "\")").isEmpty()) {
 //some logic when element is located
} else {
 //scroll to the particular element
}

我猜你是在使用iOS设备,对吗?不,我在使用android。我有一个功能,当它不可见时:expectedCondition.VisibilityOf(元素)它应该返回false,它应该向下滚动,然后再次查找。但现在,appium能够找到元素,即使不向下滚动,也可以单击屏幕上可以看到的最后一个元素(理想情况下,它尝试单击我们看不到的元素)你能提供你的代码来说明你实际上在做什么吗question@Vault23任何luckI都尝试过了,但没有帮助。它仍然返回count作为非空,并且能够找到元素