我无法在下拉列表Web VBA中选择多个项目 [英] I can't select multiple items in dropdown list web VBA
本文介绍了我无法在下拉列表Web VBA中选择多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从Intranet页面填写表格.我设法从要选择但并非同时选择的下拉列表中突出显示了该元素.我想在列表中选择三个这是我的代码:
I am trying to fill in a form from an intranet page. I have managed to highlight the element from a dropdown list I want to select but not at the same time. I want to select three in list Here's my code:
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
这是源代码(请注意,由于有很多形式,我只是提取了一部分):
Here's the source code (note that I have just put an extract since there are a lot of modalities):
<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
推荐答案
如果要按值使用,请使用attribute = value css选择器
If you want to use by value then use attribute = value css selectors
With ie.document
.querySelector("[value='ABUS']").Selected = True
.querySelector("[value='GDXE']").Selected = True
End With
这应该证明是一种快速的选择器方法.
This should prove a fast selector method.
另外,使用适当的页面等待:
Also, use a proper page wait:
While ie.Busy Or ie.readyState < 4: DoEvents: Wend
这篇关于我无法在下拉列表Web VBA中选择多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文