量角器不能在ng-click元素上使用css定位元素 [英] protractor cannot locate element with css on ng-click element

查看:195
本文介绍了量角器不能在ng-click元素上使用css定位元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

html:

 < button class =helperButton ng-scopeng-if =!isDisabled&&& ; displayHelper('none')ng-click =select('none',$ event); type =button> ×选择无< / button> 

尝试找到:

 元素(by.css('button [ng-click =select(\'none\',$ event); 

获取错误:


失败:使用定位器找不到元素:
By.cssSelector(button [ng-click = \select('none',$ event); \])


此链接提供了一个解决方案 AngularJS量角器 - 使用Ng-Click Binding在页面上查找元素,但没有函数的引用细节。

解决方案

让您的定位器基于 ng-点击不是很可靠和可读。

code> by.xpath('// button [contains(。,Select None)]')

  by.css('button.helperButton ')

或者,如果有对应用程序HTML模板的控制 - 添加 id 属性并使用:

  by.id('mybuttonid')






如果您仍然要使用 ng-click - 尝试使用 begin-with CSS选择器语法来检查 ng-click / p>

  by.css('button [ng-click ^ = select]')


html:

<button class="helperButton ng-scope" ng-if="!isDisabled && displayHelper( 'none' )" ng-click="select( 'none', $event );" type="button">  ×  Select None</button>

trying to locate with:

element(by.css('button[ng-click="select( \'none\', $event );"]'));

get error:

Failed: No element found using locator: By.cssSelector("button[ng-click=\"select( 'none', $event );\"]")

this link provides a solution AngularJS Protractor - Finding an Element on a Page Using Ng-Click Binding but does not have details to the function its referencing. Any help would be appreciated.

解决方案

Having your locator based on the ng-click is not quite reliable and readable.

Instead I would rely on the button text:

by.xpath('//button[contains(., "Select None")]')

or, on the class:

by.css('button.helperButton')

Or, if have a control over the application HTML templates - add an id attribute and use:

by.id('mybuttonid')


If you still want to use ng-click - try using starts-with CSS selector syntax to check ng-click attribute:

by.css('button[ng-click^=select]')

这篇关于量角器不能在ng-click元素上使用css定位元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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