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

前端 未结 4 392
北海茫月
北海茫月 2021-02-03 20:26

I have a button on a page that looks like:


The element has

相关标签:
4条回答
  • 2021-02-03 21:01

    Just tested this and it works:

    element(by.css('[ng-click="myFunction()"]'))
    
    0 讨论(0)
  • 2021-02-03 21:06

    I went through the Protractor API and didn't find anything related to finding an element through ng-click. I did find

    element(by.buttonText("Submit"));

    Not quite the same, but does the job in my environment.

    0 讨论(0)
  • 2021-02-03 21:06

    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 search By.css('[type="submit"]')

    0 讨论(0)
  • 2021-02-03 21:12

    If you want to use ng-show, you could try this:

    element(by.Css("button[ng-show]")); // Get element with tag < button > and has ng-show attribute
    

    or:

    element(by.Css("button[ng-show*=flag]")); // Get element with tag < button > and has ng-show attribute which contains word flag
    
    0 讨论(0)
提交回复
热议问题