我使用VBA加载一个网页并登录,用户名为
我想要使用VBA在网页的输入字段中写入搜索词。
但由于该输入字段没有名称和ID,所以我没有成功。
以下是我的代码:
myusername
,密码为mypassword
。我想要使用VBA在网页的输入字段中写入搜索词。
但由于该输入字段没有名称和ID,所以我没有成功。
以下是我的代码:
Sub MyLogin()
Dim IE As InternetExplorer
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate "https://www.example.com"
Do Until .readyState = 4
DoEvents
Loop
.document.all.Item("username").Value = "myusername"
.document.all.Item("password").Value = "mypassword"
.document.forms(0).submit
End With
Do Until IE.readyState = 4
DoEvents
Loop
Dim inputfield As HTMLInputElement
For Each inputfield In IE.document.getElementsByTagName("input")
If inputfield.Type = "text" Then inputfield.Value = "mysearch"
Next
Do Until IE.readyState = 4
DoEvents
Loop
End Sub
我想要填写的 HTML 字段:
input class="input-inboxsearch form-control" type="text" value="" placeholder="姓名,电子邮件" maxlength="71"
如何设置输入字段的值?
getElementsByClassName("input-inboxsearch form-control")
代替。 - Miqi180