vba 使用VBA登录网页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20470634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:52:13  来源:igfitidea点击:

web login using VBA

htmlcssexcel-vbavbaexcel

提问by Rueful Rabbit

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.

我正在尝试使用 VBA 访问我的 webtext a/c。第一步是尝试获取用户名和密码输入框的标签。

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.

我已经使用检查元素来确定标签,我认为它们是“用户名”和“密码”。但是,这不起作用。不幸的是,我没有 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

问候, 遗憾

回答by Santosh

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

由于登录表单位于 iframe 内,因此可能不允许直接访问控件。

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