Appium:isDisplayed()与findElements(by).size [英] Appium: isDisplayed() vs findElements(by).size

查看:391
本文介绍了Appium:isDisplayed()与findElements(by).size的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我总是使用以下方法检查appium中是否存在对象:

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;
    }

但是,我看到现在有一​​个isDisplayed()方法:

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

    driver.findElement(by).isDisplayed()

任何人都知道哪个最好用,为什么?

Anyone know which is best to use and why?

谢谢

查理

推荐答案

这主要是硒问题.使用findElements时,您正在DOM中寻找 presence 元素.但是,元素的存在仍然不能确保该元素可见.为了验证元素 display 的状态,您必须使用isDisplayed方法.例如,如果不是大页面,则不会显示页面DOM中存在的所有元素.

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.

请在W3C WebDriver中查看详细信息规范

Please see the details in W3C WebDriver specification

这篇关于Appium:isDisplayed()与findElements(by).size的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆