简体   繁体   English

量角器:按属性查找元素

[英]Protractor: Find Element by Attribute

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. ng-show属性和值是唯一用于唯一标识元素的属性和值。 The class is used in many elements... 该类用于许多元素......

I am searching for something like: 我正在寻找类似的东西:

var notValid = element(by.Attribute('ng-show', 'notValid');

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"]'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM