更新的HTML:我已经发布了完全扩展的HTML。我可以正常登录该网站。然后,我要进入的第一个字段是一个下拉列表。它有173个元素可供选择。我需要选择的元素是“ 1000000173”。我尝试了我没有成功填充下拉列表的建议。
这是更新的HTML。
<div class="form-group">
<label class="col-sm-5 control-label" for="">NPI/Provider <span class="requiredField">*</span> :</label>
<div class="col-sm-7">
<select name="NPI List" id="MultiselectDDL" style="width: 198px; height: 34px; display: none;" multiple="multiple">
<option value="1000000001">1000000001 - Some Name1</option>
<option value="1000000002">1000000002- Some Name2</option>
‘ .................................. 170 more ..............
‘
<option value="1000000173">1000000173 - Some Name173</option>
<option value="1000000174">1000000174 - Some Name174</option>
</select>
<div title="" class="chosen-container chosen-container-multi chosen-with-drop chosen-container-active" id="MultiselectDDL_chosen" style="width: 198px;">
<ul class="chosen-choices">
****** The bolded lines is what is highlighted when I chose “Inspect Element” on the dropdown list field. *******
<li class="search-field">
<input class="chosen-search-input default valid" aria-invalid="false" style="width: 178px;" type="text" value="Enter at least 3 Characters" autocomplete="off">
</li>
****** End of the highlighted HTML *******
</ul>
<div class="chosen-drop">
<ul class="chosen-results">
<li class="active-result" data-option-array-index="0">1000000001 - Some Name1</li>
<li class="active-result" data-option-array-index="1">1000000002- Some Name2</li>
<li class="active-result" data-option-array-index="2">1000000003 - Some Name3</li>
<li class="active-result" data-option-array-index="3">1000000004 - Some Name4</li>
<li class="active-result" data-option-array-index="4">1000000005 - Some Name5</li>
</ul>
</div>
我的VBA代码:
Sub SignOn_Cerner()
Dim oHTML_Element As IHTMLElement
Dim oBrowser As InternetExplorer
Dim IE As Object
Dim Element As String
Dim i As Long
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://www.azblue.com/individualsandfamilies/" ' Your webpage goes here
While IE.Busy = True Or IE.readyState <> 4: DoEvents: Wend
IE.document.getElementById("lockedcontent_0_maincolumn_1_twocolumn2fb4d204091d44aa08196ef423877fd9f_0_ToolbarUsernameControl").Value = "UserName"
Application.Wait (Now + TimeValue("0:00:01"))
IE.document.getElementById("lockedcontent_0_maincolumn_1_twocolumn2fb4d204091d44aa08196ef423877fd9f_0_ToolbarPasswordControl").Value = "Password"
Application.Wait (Now + TimeValue("0:00:01"))
IE.document.getElementById("lockedcontent_0_maincolumn_1_twocolumn2fb4d204091d44aa08196ef423877fd9f_0_ToolbarLoginButtonControl").Click
While IE.Busy = True Or IE.readyState <> 4: DoEvents: Wend
'**********This is my most recent effort ***********
Set Providor = IE.document.getElementById("MultiselectDDL_chosen")
For i = 1 To Providor.Options.Length
If Providor.Options(i).Text = "1000000173" Then
Providor.selectedIndex = i
Exit For
End If
Next i
'****************************************************
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}"
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{ENTER}"
Application.Wait (Now + TimeValue("0:00:01"))
End Sub
您可以尝试遍历页面上的每个输入标签,然后检查是否具有正确的标签。
Dim pageTag As Object
Dim pageTags As Object
Set pageTags = IE.document.getElementsByTagName("input")
For Each pageTag In pageTags ' Loop through every input tag
' Check if you have the correct input tag
If pageTag.className = "chosen-search-input default valid" And _
pageTag.Value = "Enter at least 3 Characters" Then
Dim opt As Object
For Each opt In pageTag.Options ' Loop through all options
If o.Value = "1902897820" Then ' Check option is correct
o.Selected = True
Exit For
End If
Next opt
End If
Next pageTag
希望这会有所帮助!