Javascript 量角器:按属性查找元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32826579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Protractor: Find Element by Attribute
提问by matthias
I have the following element i need to find for testing:
我需要找到以下元素进行测试:
<div class="alert alert-danger" role="alert" ng-show="notValid">Zugangsdaten eingeben</div>
How can i find this element to check visibility (ng-show)?
我怎样才能找到这个元素来检查可见性(ng-show)?
The ng-show attribute and value are the only attribute and value to identify the element uniquely. The class is used in many elements...
ng-show 属性和值是唯一标识元素的唯一属性和值。该类用于许多元素...
I am searching for something like:
我正在寻找类似的东西:
var notValid = element(by.Attribute('ng-show', 'notValid');
回答by alecxe
You can find it by.css()
:
你可以找到它by.css()
:
element(by.css('div[ng-show=notValid]'));
$('div[ng-show=notValid]'); // shortcut for the above expression
Or, by.xpath()
:
或者,by.xpath()
:
element(by.xpath('//div[@ng-show="notValid"]'));