Reputation: 23
in our angular app there are language icons to change language:
<img style="cursor: pointer; margin-right: 5px; float: left;" height="25px"
src="assets/images/english.jpg" ng-click="setLang('en')" class="">
How can I click on this icon with protractor? Based on other questions this should be the way:
element(by.css('[ng-click="setLang('en')"]')).click();
But this one throws a syntax error, because of the 'en' part. So I also tried these:
element(by.css('[ng-click="setLang(en)"]')).click();
element(by.css('[ng-click="setLang()"]')).click();
But both of these resulted in: No element found using locator
Please advise how can I click on this element?
Upvotes: 2
Views: 9101
Reputation: 473813
While escaping quotes might fix the immediate problem, but you should know that partial attribute check is also an option:
element(by.css('[ng-click*=setLang]')).click();
$('[ng-click*=setLang]').click();
where *=
means "contains", $
is a shortcut.
Upvotes: 6
Reputation: 133403
You need to escape quotes.
element(by.css('[ng-click="setLang(\'en\')"]')).click();
Upvotes: 6