How to click on a dropdown element from a list in a table using VBA

using vba with selenium I am trying to get within a dropdown box to the option value of BO_test and click. I have tried many things. Here is the last try:

Option Explicit

Private ch As Selenium.ChromeDriver

Sub test()

    Dim FindBy As New Selenium.By
    Dim ResultSections As Selenium.WebElements
    Dim ResultSection As Selenium.WebElement
    Dim ResultSections2 As Selenium.WebElements
    Dim ResultSection2 As Selenium.WebElement
    Dim TableByTag As Selenium.WebElement
    Dim tr, c, r, td, li, cc, t, columnC, rowc
    Dim size As Integer
    Dim currentWindow As Selenium.Window
    Dim html As HTMLDocument
    Set ch = New Selenium.ChromeDriver
    ch.Start baseUrl:=""
    ch.Get "/"
   With ch
   Set ResultSections2 = .FindElementsById("SPFrameWorkTable")
   For Each ResultSection2 In ResultSections2
   Application.Wait Now + TimeValue("00:00:2")
   'Debug.Print ResultSection2.Text
   Next ResultSection2
 End With
end sub

this is what the debug prints out:
Query Management
(add new query)
Set As Default
Run query when selected
Clear form when selected
Match AllMatch Any
Additional Fields Selection


<lable class="SPLayoulTable" cellspacing="0" cellpadding="0">
+ <tr> </tr>
}<tr> </tr>
<div id="SPFormDiv" class="SPFormDiv" style="width: 350px; height: 782px; overflow: auto;"> == $0
<table aginfotop="truc" class"SPLayoutTable" id="AQContentTable">
<td style="width: 20%">...</td>
<td align="left" style="width: 80%">
(select id="AQranclQueryList">
<optgroup label="My Queries">
<option value="(new)">(add new query)</option>
<option value="7c5a41f1-bala-444a-b7d0-97f5c1ce5052">BO_test</option>
* <tr> </tr>
<tr> </tr>


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try this.

Public MyElement As Selenium.WebElement

Sub Test()
    ' ...
    Set MyElement = MyBrowser.FindElementById("YourDropdownBox")
    If MyElement.IsDisplayed Then
        MyElement.AsSelect.SelectByText ("BO_test")
    End If
    ' ...
End Sub

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x