Issue
Button code in HTML:
<div class="login-new-open-button">
<button class="btn btn-primary btn-square login-new-dialog-button" ng-click="continue()" translate="">Continue</button>
</div>
The button can be found programmatically using Javascript:
document.getElementsByClassName('btn btn-primary btn-square login-new-dialog-button')
This call doesn't work:
document.getElementById('btn btn-primary btn-square login-new-dialog-button').click();
But programmatically clicking on it does not work.
Based on the connected scripts on the page, angular 10.5.10.26529 is used. Is it possible to use JavaScript to call a button click made in Angular?
Solution
For programmatically clicking button use .click () method . Also you can't define continue ( reserved keyword ) as function in js
See example =>
HTML
<div class="login-new-open-button">
<button class="btn btn-primary btn-square login-new-dialog-button" ng-click="Continue()" translate="">Continue</button>
</div>
Js
let element = document.querySelector('.btn');
element.click()
function Continue(){ // C is capital if small then keyword continue which isn't possible
alert("button clicked")
}
For selecting a particular button it is preferred to use id and getElementById method instead of class
Answered By - Sanmeet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.