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?
If you want to use
ng-show
, you could try this:or:
I went through the Protractor API and didn't find anything related to finding an element through
ng-click
. I did findelement(by.buttonText("Submit"));
Not quite the same, but does the job in my environment.
Rather than adding an ID, which I don't like to do just to provide a test hook, I would add
type="submit"
to the button and then you can searchBy.css('[type="submit"]')
Just tested this and it works: