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
    .FindElementById("AQPanelQueryList").Click
    .FindElementById("SPSideContainerTD").Click
   Next ResultSection2
      
 End With
end sub

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

—html—

<lable class="SPLayoulTable" cellspacing="0" cellpadding="0">
<tbody
+ <tr> </tr>
}<tr> </tr>
<tr>
<td>
<div id="SPFormDiv" class="SPFormDiv" style="width: 350px; height: 782px; overflow: auto;"> == $0
<table aginfotop="truc" class"SPLayoutTable" id="AQContentTable">
<tbody>
<tr>
<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>
</optgroup>
</sclcct>
</td>
</tr>
* <tr> </tr>
<tr> </tr>

Answers:

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")
    MyElement.WaitDisplayed
    If MyElement.IsDisplayed Then
        MyElement.Click
        MyElement.AsSelect.SelectByText ("BO_test")
    End If
    
    ' ...
End Sub


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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x