我有一个宏,可以让我按一下按钮就可以登录网站。然而,事实并非如此。 有人已经试图帮助我,但正如他自己所说,这有点超出了他的理解范围。所以在这里我再次尝试更多细节!
这是他发给我的最后一个代码。
Public Sub GetInfo()
Dim IE As New InternetExplorer
With IE
.Visible = True
.navigate "https://apiweb.biomerieux.com/login"
While .Busy Or .readyState < 4: DoEvents: Wend
With .document.getElementById("signupEmail")
.Focus
.Value = "xxxx"
End With
Application.Wait Now + TimeSerial(0, 0, 1)
With .document.getElementById("signupPassword")
.Focus
.Value = "yyyy"
End With
On Error Resume Next
With .document.getElementById("signupSubmit")
.Focus
.Click
End With
'.Quit
End With
End Sub
最奇怪的是,当您通过宏将凭据输入文本框并单击按钮时,该站点认为未输入凭据,即使已输入凭据也是如此。
我以前的助手认为可能网站上的部分 javascript 以某种方式搞砸了。
最佳答案
我认为这种更简单的方法足以完成工作。您需要做的就是让脚本等待第一个输入的 html 元素可用。
Sub LogMeIn()
Dim IE As New InternetExplorer, post As Object, HTML As HTMLDocument
With IE
.Visible = True
.navigate "https://apiweb.biomerieux.com/login"
While .Busy Or .readyState <> 4: DoEvents: Wend
Set HTML = .document
With HTML
Do: Set post = .querySelector("#signupEmail"): DoEvents: Loop While post Is Nothing
.querySelector("#signupEmail").innerText = "imc@yahoo.com"
.querySelector("#signupPassword").innerText = "abc12345"
.querySelector("a > #signupSubmit").Click
End With
End With
End Sub
关于html - 通过 Excel VBA 使用 JS 登录网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57112160/