I know there have been similar questions on SO about this issue, and I have been reviewing and trying many of them, but still, I'm having an issue selecting an option from a drop-down list on a website. I'm really trying to figure this out on my own, but I can't seem to get this part right.
Unfortunately, the website can only be accessed internally (of course!), so I can't share it, but I've tried to provide the HTML that I think is relevant.
What I'm trying to do is select the "Equals To" option from the list. Most of my attempts end up skipping the IF = Equals To part and advances to the next part of the VBA.
Here are a couple of my more recent attempts. (Getting an Object Required
error on the QuerySelector
approaches.
<!DOCTYPE html>
<html>
<body class="bootstrap-wrapper" style="cursor: auto;">
<div tabindex="-1" class="ui-dialog ui-corner-all ui-widget ui-widget-content ui-front dialog ui-draggable ui-resizable" role="dialog" aria-describedby="02T" aria-labelledby="ui-id-1" style="left: 328px; top: 167.5px; width: 977px; height: 603px; overflow: visible; display: block; position: absolute; z-index: 201;">
<div title="" class="chosen-container chosen-container-single chosen-container-single-nosearch chosen-with-drop chosen-container-active" id="paymentReferenceNumber_chosen" style="left: 482px; top: 279.41px; width: 200px; margin-top: 45px; margin-left: 0px; position: absolute;">
<div class="chosen-drop" style="display: block;">
<div class="chosen-search"><input type="text" readonly="" autocomplete="off"></div>
<ul class="chosen-results">
<li class="active-result result-selected" data-option-array-index="0">
Select
</li>
<li class="active-result" data-option-array-index="1">
Equals To
</li>
<li class="active-result" data-option-array-index="2">
Contains
</li>
<li class="active-result" data-option-array-index="3">
Is Empty
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
Dim inputElement As HTMLInputElement
Set inputElement = doc.querySelector( _
"html body[class=bootstrap_wrapper] tbody div[tabindex=-1] div[class=chosen-container chosen-container-single chosen-container-single-nosearch chosen-with-drop chosen-container-active] div[class=chosen-drop] ul[class=chosen-results] li[class=active-result][data-option-array-index=1]")
If Not inputElement Is Nothing Then
inputElement.Click
End If
OR
ieApp.Document.querySelector("Select[name=paymentReferenceNumber_oper] option[value=equalsTo]").Selected = True
OR
Set ElementCol = ieApp.Document.getElementsByTagName("li")
For Each ee In ElementCol
If ee.innerHTML = "Equals To" Then
ee.Click: DoEvents: Sleep 1000
Exit For
End If
Next ee
Most of the other links I have been able to select simply by using:
ieApp.Document.all.Item("adv_search_tab").Click: Sleep 1000
Or Using:
Set ElementCol = ieApp.Document.getElementsByTagName("input")
For Each ee In ElementCol
If ee.Name = "search" Then
ee.Click: DoEvents: Sleep 1000
Exit For
End If
Next ee
These are just two of the recent SO posts I have been reviewing to try to understand alternatives: VBA selecting a value from dropdown box on a webpage