问题
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