gpt4 book ai didi

javascript - 使用VBA在网页中填写用户名和密码

转载 作者:搜寻专家 更新时间:2023-10-31 22:06:45 26 4
gpt4 key购买 nike

这是我第一次尝试通过 VBA 浏览 IE 浏览器。我在尝试着: - 转到此网页 https://hb2.bankleumi.co.il/e/Login.html - 填写用户名 - 填写密码 - 点击“登录”按钮现在我收到错误消息“对象‘IWebBrowser2’的方法‘文档’失败”

我试图检查网页 html 代码中的元素并找到它们的 ID,但我想我在调用方法或接近对象时犯了一些错误。

我的代码是:

Option Explicit
Sub dataFromLeumi()
Dim myPassword As String
myPassword = "somepassword"
Dim myUserName As String
myUserName = "someusername"



Dim loginPath As String
loginPath = "https://hb2.bankleumi.co.il/e/Login.html"
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.navigate loginPath

Dim userName As Object
Set userName = IE.document.getattribute("uid")
userName.Item(0).Value = myUserName

Dim password As Object
password = IE.document.getelementbyid("password")
password.Item(0).Value = myPassword


IE.document.getelementbyid("enter").Click
End Sub

我应该在我的代码中更改什么?我错过了什么?

谢谢!

最佳答案

试试这个

Sub test()
' open IE, navigate to the desired page and loop until fully loaded
Set ie = CreateObject("InternetExplorer.Application")
my_url = "https://hb2.bankleumi.co.il/e/Login.html"

With ie
.Visible = True
.Navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400

Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop

End With

' Input the userid and password
ie.Document.getElementById("uid").Value = "testID"
ie.Document.getElementById("password").Value = "testPW"

' Click the "Search" button
ie.Document.getElementById("enter").Click

Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
End Sub

关于javascript - 使用VBA在网页中填写用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24038230/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com