web login using VBA

余生颓废 提交于 2020-01-30 00:24:10

问题


I'm trying to access my webtext a/c using VBA. The first step is trying to get the tag for the username and password input boxes.

I've used inspect elements to determine the tags and I think they are "username" and "password". However, this does not work. Unfortunately, I've no experience of CSS.

Here is my code.

Sub MyLogin()

    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .Navigate "http://www.o2online.ie/o2/login/"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        .document.all.Item("username").Value = "MyUsername"
        .document.all.Item("password").Value = "MyPassword"
        .document.forms(1).submit
    End With

End Sub

Any help appreciated.

Regards, Rueful


回答1:


As the login form is inside iframe it may not allow to access the control directly.

Try below code

Sub MyLogin()

    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .Navigate "https://www.o2online.ie/idm/login/lightBoxLogin.jsp?authn_try_count=0&contextType=external&username"

        Do Until .ReadyState = 4
            DoEvents
        Loop

        .document.all.Item("username").Value = "MyUsername"
        .document.all.Item("password").Value = "MyPassword"
        .document.forms(0).submit
        .Navigate "http://www.o2online.ie/o2/login/"
    End With

End Sub


来源:https://stackoverflow.com/questions/20470634/web-login-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!