Appium: isDisplayed() vs findElements(by).size

荒凉一梦 提交于 2019-12-11 13:19:01

问题


Traditionally I always checked for the presence of objects in appium using:

    int count = driver.findElements(by).size();
            if (count == 0) {
        Logger.LogMessage("ElementDoesNotExist: " + by, Priority.Medium);
        return true;
    } else {
        Logger.LogMessage("ElementDoesExist: " + by, Priority.Medium);
        return false;
    }

However, I see there is now a isDisplayed() method:

    driver.findElement(by).isDisplayed()

Anyone know which is best to use and why?

Thanks,

Charlie


回答1:


This is mostly Selenium question. When you use findElements you are looking for the presence element in DOM. However the element presence still not ensure that the element will visible. In order to verify the element display state you have to use isDisplayed method. For example in case the large page not all elements existing in the page DOM will be displayed.

Please see the details in W3C WebDriver specification



来源:https://stackoverflow.com/questions/30621713/appium-isdisplayed-vs-findelementsby-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!