【问题标题】:Unable to enter Username and password in webpage using VBA无法使用 VBA 在网页中输入用户名和密码
【发布时间】:2018-08-13 01:17:23
【问题描述】:

我正在尝试使用 VBA 登录网页,但无法完成。问题是在输入用户名和密码后,点击登录按钮时,网页会出现“必填字段”错误,因此基本上没有输入凭据。

我还尝试使用 IE.document.getElementById("email").setAttribute("Value") = "XX" 将值设置为属性,但仍然会引发相同的错误。我也尝试过 .focus 方法,但没有运气。

我希望我已经解释了我的问题,如有任何错误请原谅。 网页链接“”https://dashboard.stripe.com/login“”我不能共享凭据,因为它是机密的。”

Set IE = CreateObject("InternetExplorer.application")

IE.Visible = True
IE.navigate "https://dashboard.stripe.com/login"
Do Until Not IE.busy: DoEvents: Loop
Set doc = IE.document
Do While doc.ReadyState <> "complete": DoEvents: Loop

IE.document.getelementbyid("email").Value = "a@A.com"
IE.document.getelementbyid("password").Value = "a"

Set ElementCol = IE.document.getElementsByTagName("span")
For Each link In ElementCol
If link.innerHTML = "Sign in to your account" Then
link.Click
End If
Next

【问题讨论】:

  • 我在尝试登录时打了一个验证码以证明不是机器人。您确定允许“刮擦”吗?
  • 即使是这样,我认为验证码也将是一个难以克服的障碍。当然不是 VBA。
  • 我认为是。在同一系统上成功登录后,验证码只会弹出一次,但不会。您可以输入凭据并点击 sigin 吗?
  • 嗨,QHarr,请您发布您与 Selenium 一起使用的代码。

标签: vba excel internet-explorer automation


【解决方案1】:

我使用selenium basic 执行了以下操作。安装后转到 VBE > 工具 > 参考 > 添加对硒类型库的引用。

Option Explicit
Public Sub EnterInfo()
    Dim d As WebDriver, keys As New Selenium.keys
    Set d = New ChromeDriver
    Const url = "https://dashboard.stripe.com/login"
    With d
        .AddArgument "--headless"
        .Start "Chrome"
        .get url
         .FindElementById("email").SendKeys "joe.blogs@aol.com"
         .FindElementById("password").SendKeys keys.Enter
        .FindElementById("password").SendKeys "password"
        .FindElementById("password").SendKeys keys.Enter
         .FindElementByTag("form").submit
         Stop '<== Delete me
        '.Quit
    End With
End Sub

【讨论】:

  • 感谢您的帮助,但是我没有使用过 Selenium,所以我很难再走得更远,因为我必须在登录后从网页获取信息并导航到不同的选项以获取信息.
  • 嗨 QHarr,我尝试了上面的代码,但是在我启动 Web 浏览器后它给了我一个错误。(底层连接已关闭,接收时发生意外错误)所以我将浏览器更改为 IE有用。另外,您是正确的,验证码似乎是一个问题,因为它在我每次登录时都会显示。你有什么解决办法吗?
  • 感谢您的帮助。你有解决这个错误的办法吗?
  • 嗨,QHarr,已经有一段时间了。我已经解决了验证码问题。现在的问题是我需要选择下拉菜单来更改帐户,但我无法做到。任何帮助表示赞赏
  • 请发布您的验证码解决方案,这将对未来的读者有用。如果您针对当前问题发布新问题并包含 URL/HTML(使用 sn-p 工具而不是图像插入)并在此处给我留言,我很乐意提供帮助。
猜你喜欢
  • 2014-07-25
  • 2018-05-30
  • 1970-01-01
  • 1970-01-01
  • 2016-12-07
  • 2019-03-26
  • 2018-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多