Automate Login form Internet Explorer when form uses AngularJS for validation

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
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
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top