bradyboyy88
Well-known Member
- Joined
- Feb 25, 2015
- Messages
- 562
Hi,
I have scoured the internet and have not found any complete solutions to my problem. I need to automate logging into a website but unfortunately the website form uses angularjs to validate the form. Therefore, the current way my code works it does not trigger any angular events such that it shows there is a value and looks blank in the username and password hence the class for the input field still shows ng-invalid tag instead of ng-valid. Is there a way to automate login forms even for ones using angularjs? My code is below:
website form code
My VBA Code:
I have scoured the internet and have not found any complete solutions to my problem. I need to automate logging into a website but unfortunately the website form uses angularjs to validate the form. Therefore, the current way my code works it does not trigger any angular events such that it shows there is a value and looks blank in the username and password hence the class for the input field still shows ng-invalid tag instead of ng-valid. Is there a way to automate login forms even for ones using angularjs? My code is below:
website form code
Code:
<form class="ng-invalid ng-dirty ng-touched isSubmitted" id="login-form" aria-label="Login" novalidate="" _ngcontent-knt-c2="">
<div class="text-left my-3" _ngcontent-knt-c2="">
<input class="ng-valid ng-dirty ng-touched" id="website-user" aria-label="Username" required="" type="text" placeholder="User ID" _ngcontent-knt-c2="" formControlName="userName">
<!----><label _ngcontent-knt-c2=""> Required </label></div>
<div class="text-left my-3" _ngcontent-knt-c2="">
<input class="ng-valid ng-dirty ng-touched" id="website-pw" aria-label="Password" required="" type="password" placeholder="Password" _ngcontent-knt-c2="" formControlName="password">
<!---->
<label _ngcontent-knt-c2=""> Required </label>
</div><div class="mt-3" _ngcontent-knt-c2="">
<button id="btn-login" _ngcontent-knt-c2="">Login</button>
</div>
</form>
My VBA Code:
Code:
Sub login()
Const Url$ = "https://intranetsite.website.com"
Dim UserName As String, Password As String
UserName = "username"
Password = "password"
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
.navigate Url
ieBusy ie
.Visible = True
Dim oLogin As Object, oPassword As Object
Set oLogin = .document.getElementById("website-user")
Set oPassword = .document.getElementById("website-pw")
oLogin.Focus
oLogin.Click
oLogin.Value = UserName
oPassword.Focus
oPassword.Click
oPassword.Value = Password
.document.getElementById("btn-login").Click
End With
End Sub
Sub ieBusy(ie As Object)
Do While ie.Busy Or ie.readyState < 4
DoEvents
Loop
End Sub