Navigating through a custom drop-down using Selenium WebDriver: Identifying elements within DIV, UL, and LI

I need assistance automating a custom drop-down field that consists of DIV, UL, and LI elements. Select class or CSSSelector are not viable options due to the dynamic nature of the field.

    <div id="boundlist-1092" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default x-border-box x-boundlist-above" tabindex="-1" style="right: auto; left: 495px; top: 245px; height: auto; z-index: 29001; width: 150px;">
<div id="boundlist-1092-listEl" class="x-boundlist-list-ct x-unselectable" style="overflow: auto; height: auto;">
<ul class="x-list-plain">
<li class="x-boundlist-item" unselectable="on" role="option">Single</li>
<li class="x-boundlist-item" unselectable="on" role="option">Married Filing Jointly</li>
<li class="x-boundlist-item" unselectable="on" role="option">Married Filing Separately</li>
<li class="x-boundlist-item" unselectable="on" role="option">Head of Household</li>
<li class="x-boundlist-item" unselectable="on" role="option">Qualifying Widow(er)</li>
</ul>
</div>
</div>

However, the HTML code changes when the element becomes visible

    <div id="boundlist-1092" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default x-border-box x-boundlist-above" tabindex="-1" style="right: auto; left: 495px; top: 245px; height: auto; z-index: 29001; width: 150px;">
<div id="boundlist-1092-listEl" class="x-boundlist-list-ct x-unselectable" style="overflow: auto; height: auto;">
<ul class="x-list-plain">
<li class="x-boundlist-item x-boundlist-selected" unselectable="on" role="option">Single</li>
<li class="x-boundlist-item" unselectable="on" role="option">Married Filing Jointly</li>
<li class="x-boundlist-item" unselectable="on" role="option">Married Filing Separately</li>
<li class="x-boundlist-item" unselectable="on" role="option">Head of Household</li>
<li class="x-boundlist-item" unselectable="on" role="option">Qualifying Widow(er)</li>
</ul>
</div>
</div>

I would greatly appreciate any assistance with this matter.

Answer №1

In order to find the dropdown menu, you can use a method called partial matching using an XPath expression:

//div[starts-with(@id, "dropdown-")]

This code snippet is specifically looking for a div element that has an id attribute starting with dropdown-.

If you want to target specific dropdown elements within the dropdown menu, you can utilize a text match like this:

//div[starts-with(@id, "dropdown-")]//li[. = "Option 1"]

Here, the . signifies the current element's text content.

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

What is the best way to grab and retrieve a toast notification using Python's Selenium?

When the toast pop out message briefly shows for only a couple of seconds, its element is structured as: <div id class="layui-layer-content">abcde!</div> To retrieve and extract the message abcde!, what steps should be taken? ...

Struggling to create HTML divs with CSS styling

Currently working on creating a 768x240 window design. An example of what I have so far: <div class="global-tab"> <div class="image" src="link"></div> <div class="class1">{{details.name}}</div> <div class="class2" ...

Button in HTML not responsive to clicks

I'm facing an issue with my HTML button as it's not clickable at all. I suspect it may be related to incorrect div settings or a background issue. Can someone advise on what setting needs to be changed for the "sign the petition" link to become ...

applying different styles to various elements

As a newcomer to the world of jQuery, I am attempting to achieve the following goal: I have several instances of a div, and for each instance, I randomly assign a class from a predefined list in order to modify certain attributes. While this process is su ...

Navigating through a fresh batch of retrieved elements

Presently I have: two separate lists containing unused and used elements. My task is to transfer specific elements from the first list to the second list (an element can be transferred by either double-clicking on it or clicking on it while pressing a butt ...

Is it necessary to set required input if the db column can be NULL?

Is there a way to dynamically add the "required" attribute (HTML5) to an input if the chosen column cannot be null in PHP? Here's an example of what I'm trying to achieve: $result = mysqli_query($db, "SELECT * FROM table"); while($row = mysqli ...

Using PHP's header function to alter directories

So I am currently diving into PHP and facing a challenge with using headers. My setup involves using xampp for development purposes. I have a basic form where users can log in on "index.php". Upon successful login, the header function kicks in to redirect ...

What is the best way to maintain the selected row during pagination in Yii?

Currently, I am facing an issue with pagination while viewing table rows. My requirement is to select different rows from various pages and then submit the form. The problem occurs when I select rows from one page, navigate to another page to make more se ...

Exploring the integration of foreign languages within C# code?

In search of a C# expert who can assist me with a question I've been struggling to find an answer for all day. Google searches have yielded outdated information, and I need fresh insight. Wondering if there's a way to incorporate CSS and HTML in ...

Why does Assert not work when Test always succeeds?

Currently, I am delving into learning Selenium with C# and have encountered an issue with my assert function. Below is the code snippet in question: // Compare Expected Price with Actual Price string Price = "£29"; IWebElement ProductPrice = driver.FindE ...

The functionality of $(selector).css() seems to be malfunctioning

I currently have an html div element stored in a variable var rows = ""; rows += "<div>1111 : Hi there</div>"; Despite multiple attempts, I have failed to add a background color to this div using the following methods: 1. $(rows).css({&apos ...

Getting the complete XPath of an element instance in Selenium with Python is a valuable skill to have

Is it possible to obtain the complete X-path of an element instance using Selenium in Python? Input: element_inst = driver.find_element_by_link_text('Next') I need to retrieve the full X-path of element_inst Sample Output: /html/body/div[1]/ ...

Can anyone explain why my inner div's display is set to block and it is being pushed down when its parent div has

Below is a sample of my HTML+CSS code: <div> <div class="first">text</div> <div>more text</div> </div> div { display: inline; } .first { display: block; } What's interesting is that when the first ...

Choosing descendant elements in CSS styling

Is there a way to select child elements in sequence? For instance: <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li> ...

Convert HTML Tables to PDF Format

I am facing an issue with exporting my table data into a PDF using jQuery. I have made sure to install all the necessary library files, but my code doesn't seem to be working correctly. Can anyone spot any errors in my code or suggest what might be mi ...

Is it impossible to direct Selenium tests to different platforms on the Grid?

Selenium 2.38.0, Grid2, Java 1.7, TestNG Framework, Firefox 27.0, Chrome 33.0, Windows 7, Windows 8 Details - My current setup involves a Selenium Grid2 configured on 5 VMshares in a lab environment. The nodes are assigned as follows: Hub - Windows 7 No ...

Enhancing Resilience in Selenium Hubs

I manage a large Selenium Grid and I'm aiming for maximum uptime. Currently, my only weak point is the Hub - if it fails, the entire Grid goes down. I want to implement a backup system for redundancy. I'm interested in hearing about different st ...

Is it possible to apply two ngClass directives to a single div element in Angular 4?

When I click to start editing, a component is called for the editing process. In this component, I am unable to click on anything and the background turns black, which is okay. However, I would like for each ID that I select to edit to become active with a ...

What could be the reason for Firefox failing to display the border of a table when the tbody is

If Firefox isn't displaying table cell borders correctly in the presence of an empty tbody, a simple solution is to use the pseudo selector tbody:empty {display:none;} to hide the empty tbody element. This will ensure that everything is rendered as ex ...

The subscription data for nested classes appears to be displaying as undefined

In my current project, I am utilizing Angular 8 and facing an issue with a nested class. The problem arises when trying to access data from an observable subscribe operation in the child class (Players) within the main Tournament class. Until the data is r ...