Unable to enter Username and password in webpage using VBA

爷,独闯天下 提交于 2020-07-22 18:08:48

问题


I am trying to login to a webpage using VBA, but I am unable to get it done. The issue is after the username and password punched, when clicking the signin button the webpage gives an error as "Required field" so basically the credentials are not entered.

I have also tried to set the value to the attribute using IE.document.getElementById("email").setAttribute("Value") = "XX" but still is throws the same error. I have also tried .focus method too but no luck.

I hope I have explained my issue, kindly excuse for any errors. The webpage link "" https://dashboard.stripe.com/login"" I cannot share the credentials as it is confidential."

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

回答1:


I did the following with selenium basic. After install go to VBE > Tools > References > Add reference to selenium type library.

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


来源:https://stackoverflow.com/questions/51578666/unable-to-enter-username-and-password-in-webpage-using-vba

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