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>
CodePudding user response:
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