在量角器中,browser.isElementPresent vs element.isPresent vs element.isElementPresent [英] In protractor, browser.isElementPresent vs element.isPresent vs element.isElementPresent

查看:356
本文介绍了在量角器中,browser.isElementPresent vs element.isPresent vs element.isElementPresent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在量角器中,基本上有3种方法可以检查元素是否存在:

In protractor, there are, basically, 3 ways to check if an element is present:

var elm = element(by.id("myid"));

browser.isElementPresent(elm);
elm.isPresent();
elm.isElementPresent();

这些选项是否相同且可以互换,通常应该选择哪一个?

Are these options equivalent and interchangeable, and which one should be generally preferred?

推荐答案

所有功能都以类似的方式存在细微差别。以下是我发现的一些差异 -

All function in a similar way with subtle differences. Here are few differences that i found -

elm.isPresent() -

elm.isPresent() -


  1. ElementFinder 的扩展名,因此等待Angular 在页面上结算。

  2. elm 元素(定位符)或<$时,它可以工作c $ c> ElementFinder 而不是 ElementArrayFinder 。如果使用指定的 locator 返回多个元素,则在DOM中检查第一个元素是否为 isEnabled()。不接受任何参数作为输入。

  3. 最适合Angular页面和Angular元素。

  4. 在需要时首先使用查找元素是否存在。

  1. Is an extension of ElementFinder and so waits for Angular to settle on page before executing any action.
  2. It works when elm is an element(locator) or ElementFinder and not ElementArrayFinder. If multiple elements are returned using the locator specified then first element is checked if it isEnabled() in the DOM. Doesn't take any parameter as input.
  3. Works best with Angular pages and Angular elements.
  4. First preference to use whenever there is a need to find if an element is present.

elm.isElementPresent(subLoc) - (当有一个子定位器<$ c时$ c> elm )


  1. ElementFinder
  2. 用于检查是否存在作为父元素的子元素的元素。它需要一个子定位器作为参数的父 elm 。 (只有这个和 elm.isPresent()之间的区别)

  3. 最适合Angular页面和Angular元素。

  4. 当需要检查父项的子元素是否存在时,首先使用首选项。

  1. Is an extension of ElementFinder and so waits for Angular to settle on page before executing any action.
  2. Used to check the presence of elements that are sub elements of a parent. It takes a sub locator to the parent elm as a parameter. (only difference between this and the elm.isPresent())
  3. Works best with Angular pages and Angular elements.
  4. First preference to use whenever there is a need to check if a sub element of a parent is present.

browser.isElementPresent(element | |定位器) -

browser.isElementPresent(element || Locator) -


  1. webdriver的实现所以不等待角度来结算。

  2. 拿一个定位器 element 作为参数,如果使用相同的定位器找到多个元素,则使用第一个结果。

  3. 最好与非角度页面一起使用。

  4. 在非角度页面上测试时首选使用。

  1. Is an implementation of webdriver and so doesn't wait for angular to settle.
  2. Takes a locator or an element as a parameter and uses the first result if multiple elements are located using the same locator.
  3. Best used with Non-Angular pages.
  4. First preference to use when testing on non-angular pages.

上述所有检查DOM中的元素并返回 boolean r esult。虽然角度和非角度特征不会影响这些方法的使用,但是当方法默认等待角度稳定时有一个额外的优点,并且有助于避免在未找到角度元素或状态元素引用异常的情况下出现错误,等等...

All of the above checks for the presence of an element in DOM and return a boolean result. Though angular and non-angular features doesn't affect the usage of these methods, but there's an added advantage when the method waits for angular to settle by default and helps avoid errors in case of angular like element not found or state element reference exceptions, etc...

这篇关于在量角器中,browser.isElementPresent vs element.isPresent vs element.isElementPresent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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