量角器:按属性查找元素 [英] Protractor: Find Element by Attribute

查看:112
本文介绍了量角器:按属性查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到以下元素进行测试:

I have the following element i need to find for testing:

<div class="alert alert-danger" role="alert" ng-show="notValid">Zugangsdaten eingeben</div>

如何找到此元素来检查可见性(ng-show)?

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...

我正在寻找类似的东西:

I am searching for something like:

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


推荐答案

你可以找到它 by.css()

You can find it by.css():

element(by.css('div[ng-show=notValid]'));
$('div[ng-show=notValid]');  // shortcut for the above expression

或者, by.xpath()

element(by.xpath('//div[@ng-show="notValid"]'));

这篇关于量角器:按属性查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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