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

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

Answers:

Answer

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.