Autofill Angular 1.3.15 form from browser or .net

143 views
Skip to first unread message

Tom Wynne

unread,
Jul 8, 2017, 9:13:08 AM7/8/17
to Angular and AngularJS discussion
I am having trouble filling in a login form using javascript.
This is the form I want to fill using javaScript:

I need to autofill the login/password then autofill other forms for a financial application.
I can't seem to get the fields to apply the input values I submit using this code using Chrome F12:
loginForm.email.value = "te...@email.com"
loginForm.password.value = "password"

This fills the fields in but when I hit the Login button, it thinks none of the fields have been filled out. 
I am not very familiar with Angular so am in the dark.
I assumed i need to tell Angular to apply the values but none of the examples would work for this site:
I tried:
angular.element(loginForm.email).scope.$apply()
Says:
Uncaught TypeError: angular.element(...).scope.$apply is not a function

Not sure how to get to the scope object to set it to apply the input values.  If I can just get this form working, I am sure I can get the rest working as well.
Thanks


Sander Elias

unread,
Jul 10, 2017, 2:39:49 AM7/10/17
to Angular and AngularJS discussion
Hi Tom,

Why don't yu just set the default values from withing angular?

Regards
Sander

Tom Wynne

unread,
Jul 10, 2017, 1:25:55 PM7/10/17
to Angular and AngularJS discussion
I don't have access to the code, i am not the owner of the site.  I just want to fill in the username and password with javascript code (from a chromium web browser control in .net) and be able to click the submit button.  I can't figure out how to make the submit button accept the values i have entered.  There is something i need to do to register that data has been entered into the fields.
thanks
-tom

Tom Wynne

unread,
Jul 13, 2017, 7:28:45 PM7/13/17
to Angular and AngularJS discussion
After much research, this is the solution I found (at least to work with the particular web site I want to auto fill information for).
I fill in the fields:
document.getElementById('email').value="te...@email.com"
angular.element(document.getElementById('email')).triggerHandler('input')
document.getElementById('password').value="password"
angular.element(document.getElementById('password')).triggerHandler('input')

Now the button works as if the user typed in the information manually.
Hope this helps others.

-tom
Reply all
Reply to author
Forward
0 new messages