InvalidSelectorError: invalid selector: Unable to locate an element with the xpath expression

狂风中的少年 提交于 2020-01-15 10:22:50

问题


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>

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

回答1:


This error message...

invalid or illegal selector was specified

...implies that the Locator Strategy you have constructed was not a valid locator.

To locate the element with text as Tile View you can use the following xpath :

"//a[@ng-click=\"nodes.setViewType('tiles',true)\"]"

Note : As the element is an Angular element to interact with it you have to induce a waiter for the element to be clickable.



来源:https://stackoverflow.com/questions/50003307/invalidselectorerror-invalid-selector-unable-to-locate-an-element-with-the-xpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!