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

查看:21
本文介绍了Appium:isDisplayed() vs 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?

谢谢,

查理

推荐答案

这主要是 Selenium 问题.当您使用 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() vs findElements(by).size的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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