Tips for creating a dynamic CSS selector to automate text matching in Selenium using Java

I've been developing a new application that's packed with Shadow-roots. Before entering the shadow root, I could use Xpath to locate elements, but once inside the shadow root, I have to switch to CSS selectors. Check out the Root tree image below:

https://i.sstatic.net/bnhcE.png

My goal is to create a CSS selector that can precisely match the button name like this:

div[text='Introduction']

Is it even possible? If so, what would be the correct CSS selector syntax to match the button names?

In the left navigation panel, there are multiple buttons such as Introduction, Summery, and Reports. I'm aiming to write a CSS selector that can parameterize them based on just the button text. This way, using a single CSS selector, I'll be able to click on any of these buttons by passing the respective button text.

Answer №1

It is not mandatory to limit yourself to CSS selectors within a shadow-root. Feel free to utilize any type of locators you prefer.

Furthermore, it is impossible to pinpoint an element based on its text content using a CSS selector.

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 about a lightbox with enhanced jQuery features?

As a newcomer to jQuery, I've never experimented with lightboxes before. However, I was tasked with creating something fun for April Fools' Day at work. Naively, I accepted the challenge thinking it would be simple, but now I find myself struggli ...

Building a Compact Dropdown Menu in Bootstrap

I am looking to implement a compact Bootstrap dropdown feature, but I am unsure of how to do it. Take a look at this image for reference. base.html: <a class="text-light" data-bs-toggle="dropdown" aria-expanded="false&qu ...

Managing the vertical positioning of grid items: tips and tricks

Is there a way to make the hexagons in my grid responsive to the layout, so that their height and width remain fixed relative to their container? Currently, they are overflowing from the grid container as shown in this jsfiddle: https://jsfiddle.net/gv5wc1 ...

It is impossible for me to utilize inline SVG as a custom cursor in CSS

Below is the code I have written. I am attempting to change the cursor using an inline SVG, but it doesn't seem to be working as expected. However, when I use the same code as a background, it works perfectly: .container { width: 50vw; height: ...

"Controlling Selected Options in Bootstrap Dual Listbox: A Guide to Limiting Choices

I am utilizing the Bootstrap Dual Listbox plugin to assist users in selecting specific options. I have successfully integrated this plugin into my project. However, I encountered an issue when attempting to impose a limit on the number of options a user ...

iPhone height is not correct

One issue I faced was when trying to view a webpage in landscape mode on iPhones (specifically testing on model SE, but it appears that many people are experiencing the same problem with other iPhone models). I have created a simple example below, consist ...

Utilizing JavaScript to enable a Bootstrap 5 dropdown menu to open on hover for desktop users and be clickable for mobile users

I am currently using Bootstrap 5 to design a website and I'm facing an issue with creating a navbar dropdown. On desktop, I want the dropdown to open on hover and redirect the user to a new page when clicked. However, on mobile devices, I only want th ...

Material-ui v5's DataGrid now includes a new filter icon feature

The current default setting for the new DataGrid is to only display a filter icon when hovering over the column header with an applied filter. In contrast, the previous version had the icon visible at all times. For reference, you can view the Codesandbox ...

What could be causing the need to restart the server every time a style change is made?

I'm currently developing a NextJS application that utilizes PurgeCSS. It's quite frustrating because every time I tweak the classname of a component, I have to restart the server. Here is a snippet from my postcss.config.js: plugins: [ [ ...

Ensure that the content inside the centrally aligned div is also aligned at the

Looking for a way to center a box on a website I'm designing? Instead of aligning it based on existing centering, use the following HTML / CSS code to ensure that the white box is perfectly centered on the page. .loading { position: fixed; z-in ...

Trouble locating element using XPATH in Selenium with Python

I'm currently attempting to use Python Selenium to select an element, but the XPATH has a different format that I'm unfamiliar with when it comes to selection. Below is the HTML code of the element, with an image representation provided below: & ...

Is it feasible to bypass tags that have already been parsed and proceed with the newer ones in Python?

Imagine this scenario where I have the given HTML structure: <div class="class1"> <div class="some multiple classes here"> <div class="some multiple classes here"> <ul class="other classes"> ...

Why is my Horizontal Bootstrap Navbar appearing vertically on my website?

Currently developing my portfolio page and aiming to incorporate Bootstrap's horizontal navbar at the top of each webpage. However, for some reason it is showing up vertically instead of horizontally as intended. If you're interested, feel free ...

Improper Placement of CSS in Google Chrome

I'm facing an issue with my login form that displays perfectly fine in all browsers except Google Chrome. In Chrome, it tends to get distorted more often than not. CSS * { margin: 0; padding: 0; width: auto; } body { background: #E8 ...

Issues with the functionality of media queries

I'm trying to create a slider on my website using media queries to adjust the image size. Here's my CSS code: #myCarousel .item { height:400px; } #slide1{ background:url("bdpics/CoxBazar/new folder/coxE_4_md.jpg") top center no-repeat; } ...

Is there a way to eliminate the additional and varying pseudo-padding on text inputs in both Webkit and Gecko browsers?

The issue I'm facing is specific to input[type="text"] elements in Webkit. No matter what adjustments I make, it seems like there is an additional padding: 1px 0 0 1px (top and left only) applied to the element. A similar anomaly occurs in Gecko as w ...

Creating a two-column table in JqueryMobile

Looking to create a responsive table with 2 columns using jquery mobile. I tried aligning one column to the left and the other to the right, but instead, both columns appeared stacked vertically. Is there a way to display a 2-column table with proper ali ...

From structured CSS to streamlined LESS syntax

Being a UX designer, my goal is to streamline my workflow. I aim to transition from HTML to well-structured CSS to LESS as efficiently as possible. The concept is to input HTML, generate CSS, compile it to LESS, style it, and then recompile it back to CSS ...

Utilizing Python and Selenium to retrieve specific fragments of messages from Yopmail

Is it possible to extract a specific part using Python Selenium? I've been able to do it with Pyautogui, but I'm looking for a way to accomplish it without that tool. Any suggestions? https://yopmail.com/ Please place in the inbox tab. jenniferw ...

How do I customize the default styling of a single slider in react-slick?

Looking to enhance the look of slick carousels by customizing prev/next arrows and controlling their position? I'm currently using nextjs13, chakra-ui, react-slick, and vanilla extract. An effective way to customize arrow styles is by passing an arro ...