Podolszki Ákos Podolszki Ákos - 20 days ago 5
Javascript Question

Selecting an element by ng-click in Protractor

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?

Answer

You need to escape quotes.

 element(by.css('[ng-click="setLang(\'en\')"]')).click();