您好我正在努力通过Excel宏在Internet Expolrer中提交表单。 "搜索"这里的按钮没有" ID"。这就是为什么我不能使用.Click方法来实现" serialNumber" ID。你能帮忙用Visual Basic代码吗?如何在窗口中输入数据并点击"搜索"按钮按vba代码。谢谢。
这是我的HTML代码:
<div class="form" data-bind="enterkey: search">
<form action="https://somewebpage.com/application/serialnumbersearch/Search" method="get">
<label>
Serial number:
</label>
<input name="serialNumber" id="serialNumber" type="text" data-bind="value: serialNumber">
<input type="submit" value="Search" data-bind="click: search, disable: isLoading()">
</form></div>
我的代码:
Private Sub IE_Autiomation()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim iframe As HTMLDocument
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = True
' Send the form data To URL As POST binary request
IE.navigate "https://somepage.com/Tools/Pages/Serialnumbersearch.aspx"
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Application.StatusBar = "Search form submission. Please wait..."
Set iframe = IE.document.getElementById("alexIFRAME").contentWindow.document
Set objCollection = iframe.getElementsByTagName("input")
i = 0
While i < objCollection.Length
If objCollection(i).Name = "serialNumber" Then
' Set text for search
objCollection(i).Value = "excel vba"
Else
If objCollection(i).Type = "submit" And _
objCollection(i).Name = "" Then
' "Search" button is found
Set objElement = objCollection(i)
End If
End If
i = i + 1
Wend
objElement.Click ' click button to search
' Wait while IE re-loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
' Show IE
IE.Visible = True
' Clean up
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
Application.StatusBar = ""
End Sub