Instructions for selecting a dropdown item within a table using VBA

Struggling to navigate a dropdown box using VBA with Selenium? Specifically, trying to select the option value of "BO_test" and click on it? Here's some sample code that I've been experimenting with:

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 the output from the debug: 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>
</select>
</td>
</tr>
* <tr> </tr>
<tr> </tr>

Answer №1

Give this a shot.

Public MyElement As Selenium.WebElement

Sub TryOut()
    ' ...
    
    Set MyElement = MyBrowser.FindElementById("YourSelectionBox")
    MyElement.WaitDisplayed
    If MyElement.IsDisplayed Then
        MyElement.Click
        MyElement.AsSelect.SelectByText ("BO_test")
    End If
    
    ' ...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that the text stays aligned at the center within an `<li>` tag, especially when there is an image along with the text within the element

I have a basic list structured like this: <ul> <li>ONE</li> <li>TWO</li> <li>THREE</li> <li>FOUR</li> <li>FIVE</li> <li>SIX</li> <li><hr&g ...

Including a JavaScript file in an HTML document initiates a server request, which can lead to potential errors

I am currently developing a web application using Express and Node.js on the backend, with EJS as the templating engine on the frontend. Here is a snippet of my app.js file: app.get('/book/:id', (req, res)=>{ var book_id = req.params.id; cons ...

Utilizing Blurred Images in the Header

I want to create a blurred background image with text and buttons on top of it, but the blur effect is also affecting the text and buttons. I'm not sure how to keep them separate. header { background: url("street-238458.jpg") no-repeat center; ...

When transitioning from Native to Webview in Appium, an error arises

While attempting to switch from Native to Webview, an error occurs with the following code: code Set contextNames = driver.getContextHandles(); for (String contextName : contextNames) { System.out.println(contextName); //prints out someth ...

Adjust the width of your table content to perfectly fit within the designated width by utilizing the CSS property "table width:

Example of a table <table> <tr> <td>Name</td> <td>John</td> <td>Age</td> <td>25</td> <td>Job Title</td> <td>Software Engineer ...

Using JQuery to animate a division towards the left

Currently, I am in the process of developing a website that is meant to incorporate JQuery Animations. My goal is to create an animation effect for the menu items so that each item moves to the right when the mouse hovers over it. Despite my efforts to fi ...

Prevent Image Distortion in HTML and CSS

Is there a way to prevent a background image from stretching in html/css? Take a look at the current code below, where the image behind a button appears like this: #backImage6{ /*@editable*/background-image:url(https://images.unsplash.com/phot ...

Setting the 'checked' status of a select option in a Bootstrap modal dynamically

I recently implemented a Bootstrap modal that is triggered by a link passing multiple parameters to display a select list for users to rate between 1 and 5. While this functionality is working as expected, I now face the challenge of having the select menu ...

How can I use jQuery to reload the page only at certain intervals?

I'm currently using jQuery to reload a page with the code provided below: <script type="text/javascript"> $(document).ready(function(){ setInterval(function() { window.location.reload(); }, 10000); }) & ...

Z-index in iframe: Lightning fast

Here's the issue: When I use Flash on a website and create a dialog box that should be above all other elements, I typically just adjust the z-index for the dialog box. However, in IE6 it's necessary to set a transparent wmode for the flash. The ...

Adjusting content of list item

I created a list: <ul> <li id="one"></li> </ul> Afterwards, I used jQuery to change the text inside the list item: $("#one").text("one"); Unfortunately, the text is not updating as expected. I also attempted using .val() but it ...

Error encountered when loading Selenium and GeckoDriver on a live server: Issue with finding matching capabilities

I am facing an issue while trying to build a web application on a Linux webserver using Selenium with Firefox. The application works perfectly fine when I run it on the server "localhost:5000", but encounters an error when I try to run it on "127.0.0.1:80" ...

The color scheme detection feature for matching media is malfunctioning on Safari

As I strive to incorporate a Dark Mode feature based on the user's system preferences, I utilize the @media query prefers-color-scheme: dark. While this approach is effective, I also find it necessary to conduct additional checks using JavaScript. de ...

Issues with Bootstrap-slider.js functionality

I'm having trouble getting the bootstrap-slider.js library from to function correctly. All I see are textboxes instead of the slider components. You can view an example at I have verified that the CSS and JS files are pointing to the correct direc ...

Tips for creating a clickable A href link in the menu bar that triggers an accordion to open in the body when clicked - html

Is there a way to open the first accordion when clicking on the "open 1st accordion" link, and do the same for the second link? The accordions themselves work perfectly fine, I just need a way to trigger them from outside their scope by clicking on links i ...

Can Angular Flex support multiple sticky columns at once?

I am trying to make the information columns in my angular material table stay sticky on the left side. I have attempted to use the "sticky" tag on each column, but it did not work as expected. <table mat-table [dataSource]="dataSource" matSort class= ...

Retrieve the final element within an HTML framework

Is it possible to target the final div along with its content exclusively using CSS and child combinators? My goal is to apply custom styling to it. <body> <div> <div> <div> <div> <div> ...

Customizing HTML element tags in MUI: Best practices

Using the most recent version of MUI (v5) and incorporating CssBaseline from @mui/materials. Typically, in CSS, I would set up my styles like this: body, html, #root { width: 100%; height: 100%; min-height: 100%; margin: 0; padding: 0; font-siz ...

What is the best way to access a menu item located inside a frame using either Selenium Webdriver or Cypress?

I'm encountering issues with clicking a menu button on a work website. Whether I use Selenium or Cypress, errors persist. With Cypress, an uncaught exception error arises along with a message stating that the (html) document cannot be read; while usin ...

Giving 100% height to the parent element without specifying a specific height

Struggling with some height adjustments while working on my CSS using HTML5 and CSS3. HTML 1. <section> 2. <article> 3. Article 1 4. </article> 5. <article> 6. Article 2 7. </article> 8. ...