InvalidSelectorError:无效选择器:无法使用xpath表达式定位元素 [英] InvalidSelectorError: invalid selector: Unable to locate an element with the xpath expression
本文介绍了InvalidSelectorError:无效选择器:无法使用xpath表达式定位元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是html代码段元素
Following is html snippet element
<a ng-click="nodes.setViewType('tiles',true)">
<span class="fa fa-check Tick-Inactive" ng-class="nodes.viewType == 'tiles'? 'Tick-Active':'Tick-Inactive'" style=""></span>
Tile View
</a>
尝试使用Java脚本转义符在定位器中使用ng-click或ng-class.但显示选择器无效或非法
Trying to use ng-click or ng-class in locators using java script escape characters. But it showing invalid or illegal selector was specified
element(by.xpath("//a[contains(@ng-click,'nodes.setViewType(\'tiles\',true)')]"));
element(by.css("span[ng-class^=nodes.viewType == \'tiles\']"));
element(by.xpath("//a[contains(@ng-click,'nodes.setViewType%28%27tiles%27%2Ctrue%29')]"));
推荐答案
此错误消息...
invalid or illegal selector was specified
...表示您构建的定位器策略不是有效的定位器.
...implies that the Locator Strategy you have constructed was not a valid locator.
要找到文本为 Tile View 的元素,可以使用以下 xpath :
To locate the element with text as Tile View you can use the following xpath :
"//a[@ng-click=\"nodes.setViewType('tiles',true)\"]"
注意:由于该元素是与 Angular 进行交互的元素,因此必须诱使该元素可点击的服务生.
Note : As the element is an Angular element to interact with it you have to induce a waiter for the element to be clickable.
这篇关于InvalidSelectorError:无效选择器:无法使用xpath表达式定位元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文