See this screenshot, is this the one to click on drop down HTML Code after selecting Metrics-1 from Drop down menu I am trying to select value from combo box on internet explorer using vba. When website gets opened, combo box has default value. I want to select last value from combo box. I inspected it's elements and found unique id. There is no option lists in browser's inspect element nor index number but combo box has 8 lists showing.
I tried getElementById("Unique_Id").innerText = "Last_value"
and it gives the value in combo box. But problem is when I select the same using mouse the next combo box gets refreshed and gives relevant results based on current combo box value selection. After doing the same through vba, next combo box didn't get refresh. It shows the results of default value selected in combox, not for the value I gave using innerText
.
Please note that. I have tried .onfocus
, .click
, .selectedindex
to get the results for the selected value but nothing worked.
Drop down:
•<div id="reportsDropDownContainer" class="col-lg-4 col-md-4 col-sm-4 col-xs-4"›
• <div class="form-group"›
<label id="reportsDropDownLabel" class="control-laber> Presets</label>
• <div class="Select has-value Select--single">
• <div class="Select-contror>
• <div class="Select-multi-value-wrapper" id="react¬select-4—value"›
• <div class="Select-value"›
<span class="Select-value-label" role="option" aria-selected="true" id="react-select-4--value-item">Activity History</span> == $0
</div>
<div aria-expanded="false" aria-owns aria-activedescendant="react-select-4--value" aria-disabled="false" class="Select-input" role= "combobox" tabindex="0" style="border: Opx; width: ipx; display: inline-block;"></div>
</div>
Sub ABC()
Dim IE As SHDocVw.InternetExplorer
Dim HTMLdoc As MSHTML.HTMLDocument
Dim HTMLInputs As MSHTML.IHTMLElementCollection
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLTags As MSHTML.IHTMLElementCollection
Dim HTMLTag As MSHTML.IHTMLElement
Dim e As Object
Set IE = New InternetExplorerMedium
IE.Visible = True
IE.navigate "https://abc.domain.com"
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("00:02:00")) 'After ready state, takes time to load the some contents.
Set HTMLdoc = IE.document
Set HTMLTags = HTMLdoc.getElementsByTagName("a")
For Each HTMLTag In HTMLTags
If HTMLTag.getAttribute("href") = "/site/xyz/Reports" Then
HTMLTag.Click
Exit For
End If
Next
Application.Wait (Now + TimeValue("00:00:02"))
IE.document.getElementById("react-select-4--value-item").Item.Value = "Metrics-1" 'It's not working. Showing run time error
IE.document.getElementById("react-select-4--value-item").Value = "Metrics-1" 'It's not working. Showing run time error
IE.document.getElementById("react-select-4--value-item").selectedIndex = 8 'It 's not working. Showing run time error
Set HTMLInput = HTMLdoc.getElementById("react-select-4--value-item")
HTMLInput.innerText = "Metrics-1"
HTMLInput.Focus
HTMLInput.FireEvent "onchange"
HTMLInput.Click
'Tried the same in another way using aria-activedescedant.
Set HTMLInputs = HTMLdoc.getElementsByTagName("div")
For Each HTMLInput In HTMLInputs
If HTMLInput.className = "Select-input" And HTMLInput.role = "combobox" And HTMLInput.getAttribute("aria-activedescendant") = "react-select-4--value" Then
Debug.Print HTMLInput.getAttribute("aria-activedescendant")
HTMLInput.getAttribute("aria-activedescendant").Value = "react-select-4--Option-10"
Debug.Print HTMLInput.getAttribute("aria-activedescendant")
End If
Next
HTMLInput.getElementById("react-select-4--value-item").setAttribute.Value = "Metrics-1"
End Sub