AngularJS Protractor - Finding an Element on a Page Using Ng-Click Binding

Lloyd Banks picture Lloyd Banks · Jul 17, 2014 · Viewed 50.2k times · Source

I have a button on a page that looks like:

<button ng-click="myFunction()" ng-show="flag">
    Submit
</button>

The element has no ID.

Is there a way to find this element using the function bound to Ng-Click? Or do I have to assign an ID to this element to locate it using Jasmine / Protractor?

Answer

Ted Warner picture Ted Warner · Sep 3, 2014

Just tested this and it works:

element(by.css('[ng-click="myFunction()"]'))