Fill user name and password in a webpage using VBA

This is my first try to navigate a IE browser through VBA. I am trying to: - go to this webpage - fill in the username - fill the password - click the "login" button for now I'm getting the error "Method 'Document' of object 'IWebBrowser2' failed"

I tried to inspect the elements in the html code of the webpage and found their ids but I suppose I'm making some mistake in invoking the methods or approaching the object.

my code is:

Option Explicit
Sub dataFromLeumi()
    Dim myPassword As String
    myPassword = "somepassword"
    Dim myUserName As String
    myUserName = "someusername"

    Dim loginPath As String
    loginPath = ""
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.application")
    IE.Visible = True
    IE.navigate loginPath

    Dim userName As Object
    Set userName = IE.document.getattribute("uid")
    userName.Item(0).Value = myUserName

    Dim password As Object
    password = IE.document.getelementbyid("password")
    password.Item(0).Value = myPassword

End Sub

What should I change in my code? What do I miss out?




Try this

Sub test()
' open IE, navigate to the desired page and loop until fully loaded
    Set ie = CreateObject("InternetExplorer.Application")
    my_url = ""

    With ie
        .Visible = True
        .Navigate my_url
        .Top = 50
        .Left = 530
        .Height = 400
        .Width = 400

    Do Until Not ie.Busy And ie.readyState = 4

    End With

' Input the userid and password
    ie.Document.getElementById("uid").Value = "testID"
    ie.Document.getElementById("password").Value = "testPW"

' Click the "Search" button

    Do Until Not ie.Busy And ie.readyState = 4
End Sub


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.