如何使用量角器检查元素是否可见? [英] How to use protractor to check if an element is visible?
问题描述
我正在尝试使用量角器测试元素是否可见.下面是元素的样子:
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()).toBe(true);
记住量角器的 $
不是 jQuery 并且 :visible
不是 yet 的一部分 可用的 CSS 选择器 + 伪选择器
Remember protractor's $
isn't jQuery and :visible
is not yet a part of available CSS selectors + pseudo-selectors
更多信息请访问 https://stackoverflow.com/a/13388700/511069
这篇关于如何使用量角器检查元素是否可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!