如何使用量角器来检查元素是否可见? [英] How to use protractor to check if an element is visible?

查看:164
本文介绍了如何使用量角器来检查元素是否可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试一个元素使用量角器是可见的。这里的元素是什么样子:

I'm trying to test if an element is visible using protractor. Here's what the element looks like:

<i class="icon-spinner icon-spin ng-hide" ng-show="saving"></i>

当在Chrome控制台,我可以用这个jQuery选择,以测试该元素是可见的:

When in the chrome console, I can use this jQuery selector to test if the element is visible:

$('[ng-show=saving].icon-spin')
[
<i class=​"icon-spinner icon-spin ng-hide" ng-show=​"saving">​</i>​
]
> $('[ng-show=saving].icon-spin:visible')
[]

然而,当我尝试做相同的量角器,我在运行时出现此错误:

However, when I try to do the same in protractor, I get this error at runtime:

InvalidElementStateError: 
invalid element state: Failed to execute 'querySelectorAll' on 'Document': 
'[ng-show=saving].icon-spin:visible' is not a valid selector.

这是为什么无效?我如何用量角器检查知名度?

Why is this not valid? How can I check for visibility using protractor?

推荐答案

这应该这样做:

expect($('[ng-show=saving].icon-spin').isDisplayed()).toBeTruthy();

记住量角器的 $ 不是jQuery和:可见不是的没有的一可用的CSS选择器的一部分+伪选择

Remember protractor's $ isn't jQuery and :visible is not yet a part of available CSS selectors + pseudo-selectors

http://stackoverflow.com/a/13388700/511069

这篇关于如何使用量角器来检查元素是否可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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