对于你的问题,如果你无法找到元素的ID或者通过类名来操作,可以尝试以下几种方法来填充文本框并点击发送。
Dim objIE As Object
Dim objElement As Object
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.navigate "http://example.com"
Do While objIE.Busy = True Or objIE.readyState <> 4
DoEvents
Loop
' 使用XPath定位元素
Set objElement = objIE.document.SelectSingleNode("//input[@name='textbox']")
If Not objElement Is Nothing Then
' 填充文本框
objElement.Value = "要填充的文本"
' 点击发送按钮
objElement.form.submit
End If
Set objIE = Nothing
Dim objIE As Object
Dim objElement As Object
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.navigate "http://example.com"
Do While objIE.Busy = True Or objIE.readyState <> 4
DoEvents
Loop
' 使用CSS选择器定位元素
Set objElement = objIE.document.querySelector("input[name='textbox']")
If Not objElement Is Nothing Then
' 填充文本框
objElement.Value = "要填充的文本"
' 点击发送按钮
objElement.form.submit
End If
Set objIE = Nothing
Dim objIE As Object
Dim objElement As Object
Dim objElements As Object
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.navigate "http://example.com"
Do While objIE.Busy = True Or objIE.readyState <> 4
DoEvents
Loop
' 定位所有input标签
Set objElements = objIE.document.getElementsByTagName("input")
For Each objElement In objElements
' 判断元素的属性值是否匹配
If objElement.getAttribute("name") = "textbox" Then
' 填充文本框
objElement.Value = "要填充的文本"
' 点击发送按钮
objElement.form.submit
Exit For
End If
Next
Set objIE = Nothing
以上是三种常用的方法来定位元素并填充文本框并点击发送。根据你的具体情况,选择适合的方法来解决问题。
领取专属 10元无门槛券
手把手带您无忧上云