我的任务是自动填写Web表单。我能够打开表格,并能够从下拉菜单中选择选项并能够填写表格。下拉菜单有多个选项,并根据下拉菜单中的选择显示表单。我可以通过VBA编码从下拉菜单中选择选项,但是表单没有扩展。尽管可以通过从下拉菜单中选择鼠标来扩展它。
我写了以下代码:
Sub FilltheForm1()
Dim IE As SHDocVw.InternetExplorer
Dim IE2 As SHDocVw.InternetExplorer
Set IE = New InternetExplorer
Set IE2 = New InternetExplorer
IE.Visible = True
IE.navigate "My URL"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Dim Doc As MSHTML.HTMLDocument
Set Doc = IE.document
Doc.getElementsByTagName("select").Item("userType").Value = "SERVICE_PROVIDER"
Doc.getElementsByTagName("Input").Item("firstName").Value = "A"
Doc.getElementsByTagName("Input").Item("middleInitial").Value = "A"
Doc.getElementsByTagName("Input").Item("lastName").Value = "A"
Doc.getElementsByTagName("select").Item("company").Value = "HCL"
Doc.getElementsByTagName("Input").Item("companyEmail").Value = "A"
Doc.getElementsByTagName("Input").Item("address").Value = "A"
Doc.getElementsByTagName("Input").Item("city").Value = "A"
Doc.getElementsByTagName("Input").Item("stateProvince").Value = "A"
Doc.getElementsByTagName("Input").Item("zipPostalCode").Value = "A"
Doc.getElementsByTagName("select").Item("country").Value = "INDIA"
Doc.getElementsByTagName("Input").Item("phone").Value = "A"
Doc.getElementsByTagName("textarea").Item("reasonForRequestingAccess").Value = "A"
End Sub
Web表单的HTML代码:
<tr>
<td class="textAlignRight">
<p class="pBold">User Type:<sup>*</sup></p></td>
<td colspan="2" align="left"> <select name='userType' class="selectDropDown" onChange=refreshPage()>
<option value= 'PLEASE SELECT USER TYPE' selected ="selected">
答案 0 :(得分:1)
您可能需要触发OnChange事件以模仿用户交互。
ie.document.querySelector("[name='userType']").FireEvent "onchange"