我正在尝试从Intranet页面填写表格。 我设法从要选择但不同时选择的下拉列表中突出显示了该元素。我想在列表中选择三个 这是我的代码:
Sub GetLTRTable()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
ie.navigate "myurl"
Do Until ie.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
Dim Fields As Object
Set Fields = ie.Document.all.Item("ADFields")
Fields.Checked = True
Dim organization As Object
Set organization = ie.Document.all.Item("Org")
organization.selectedindex = 0
Dim Modality As Object
Set Modality = ie.Document.getElementsByName("Modality")(0)
With Modality.Value = "'GDXE'"
Modality.Value = "'ABUS'"
Modality.Value = "'A&S'"
End With
ie.Document.getElementsByName("Action").Item(1).Click
这是源代码(请注意,由于有很多形式,我只是提取了一部分):
<select name="Modality" multiple="" size="4"><option value="'ALL'" selected="">ALL</option>
<option value="'A&S'">A&S</option>
<option value="'ABUS'">ABUS</option>
<option value="'ACS'">ACS</option>
<option value="'ANES'">ANES</option>
</select>
感谢您的帮助
Corentin
答案 0 :(得分:0)
在这种情况下,您不需要更改Modality
的值,而是将选项设置为“ selected”:
Modality.getElementsByTagname("option").item(0).selected = "selected"
答案 1 :(得分:0)
如果要按值使用,请使用attribute = value css选择器
With ie.document
.querySelector("[value='ABUS']").Selected = True
.querySelector("[value='GDXE']").Selected = True
End With
这应该证明是一种快速的选择器方法。
另外,使用适当的页面等待:
While ie.Busy Or ie.readyState < 4: DoEvents: Wend