Tips on utilizing the CSS 'or' operator within Python Selenium

I am looking to locate all the a tags that have classes containing 'lime', 'green', or 'busy'.

Here is the code snippet I currently have:

bs_tables = driver.find_elements_by_css_selector ("div#tables a[class*='lime'][class*='busy'][class*='green']")

However, it appears to be using the 'and' operator instead of the 'or' operator.

Does anyone know how to use the 'or' operator in this scenario?

Answer №1

Finally, after numerous attempts, I have discovered the answer:

bs_tables = driver.find_elements_by_css_selector ("div#tables a[class*='lime'],[class*='busy'],[class*='green']")

Success at last!

Answer №2

When using commas in CSS selectors, remember that it acts as the OR operator for the entire selector, not just a part of it. For example:

div#tables a[class*='lime'],
div#tables a[class*='busy'],
div#tables a[class*='green']

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

Unable to use Selenium to upload a file

I am having some trouble uploading a pdf file as I keep encountering an exception: Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot focus element Shown below is the piece of code causing the issue: public clas ...

What is the best way to emphasize the selected color?

I am having trouble with setting the focus and active properties for an input element. Even after selecting a color, the highlight does not appear. However, the hover property is working fine. Here is the code I have used to implement the highlight proper ...

What causes the sudden shift in shape for a numericInput corner from round to 90 degrees in shinydashboard?

After creating a numericInput and a selectInput field using scripts in both shiny and shinydashboard, I noticed that the corner of the numericInput changes to 90 degrees in shinydashboard. For reference, you can view screenshots of both examples below: ht ...

Transform radio inputs into buttons when they are enclosed within a label element

This is my HTML code: <div class="product-addon product-addon-extra-tip"> <p class="form-row form-row-wide addon-wrap-2004-extra-tip-0-0"> <label><input type="radio" class="addon-radio" name="addon-2004-extra-tip-0[]" valu ...

Trouble with HTML and CSS design layout

I'm struggling to create a responsive design for my webpage. The layout should consist of black blocks that display images. Ensuring the layout adapts to different screen sizes is proving challenging. It needs to maintain its shape on smaller screens ...

Ensure that outlines are visible only when navigating with the tab key using tabindex

Currently, I am working on enhancing the accessibility of my website by improving navigation using the tab button. I have implemented tabindex to manage this, but I have noticed that elements with tabindex display an outline both when clicked and when focu ...

What is the distinction between using localStorage and storing individual files when clicking?

Recently, I created a basic jQuery script that stores values such as "voted1", "voted2", and "voted3" in localStorage. However, I encountered an issue where all values are stored simultaneously on click, whereas I require them to be stored individually per ...

How is it that the browser can determine my preferred font when all of them are labeled as Roboto?

Forgive my lack of expertise, but I have a question to ask... I've come across many examples that use the following method to load fonts from a local server: @font-face { font-family: "Roboto"; src: local(Roboto Thin), url("#{$robot ...

Rotating the icon in Bootstrap Accordion upon opening

I am trying to customize a Bootstrap 4 accordion by conditional rotating the icon to point up when it is open and back down when closed. I managed to achieve this using CSS, but now I need to implement it conditionally based on active states rather than ev ...

Having trouble clicking the Save button when trying to download an Excel file with Webdriver in Java

I am facing an issue where I am unable to click on the Save button while trying to download an Excel file using Webdriver in Java, as shown in the attached screenshot. Despite searching for answers in various forums, I have not been able to find a solution ...

Tips for choosing a button based on its text with selenium 4.8

I've encountered a roadblock while trying to automate contact requests on LinkedIn using Python and Selenium. Specifically, I'm struggling with the "ADD CONTACT" part as I am unsure of how to select a button based on its visible text. The tutoria ...

Having trouble finding the element during Selenium JavaScript testing

I need help testing a JavaScript script using Selenium, but I am running into an issue. I cannot seem to find a specific element that I want to click on. Here is a snippet of my JS code where I am trying to click on the Shipping option. I have tried us ...

Why aren't the input fields on my HTML form matching the styling of the PureCSS website?

I added the pure-css to my html template and created a simple form. I expected it to look just like the form on the PureCSS website. However, the buttons are nicely styled but the input elements in the form appear plain. No rounded corners or highlights. ...

Classic design of the shadow element

I have main.js and index.html below class CustomTagA extends HTMLElement { constructor() { super(); const shadow = this.attachShadow({mode: 'open'}); const wrapper = document.createElement('h1'); ...

An issue occurred when attempting to utilize the Android Driver with the EMulator

I am a beginner in using Selenium and facing an issue while trying to automate an application. When running my code, I encounter the following exception: Error log: org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remo ...

Collapse in Bootstrap without any Animation

How can I add animation to the Bootstrap Collapse feature on my website? I am using an icon from the Font Awesome library to trigger the collapse effect, but currently, it just pops up without any animation. What could be causing this issue? You can view ...

The ::before pseudo element is malfunctioning when used in the makeStyles function

I am currently utilizing the makeStyles function in React, but I seem to be facing an issue where the content within the ::before pseudo-element is not displaying. Strangely enough, when the content is an image it works fine, but text does not render. Jus ...

I'm encountering an issue with byebug not functioning properly alongside selenium in Ruby

require 'selenium-webdriver' require 'byebug' byebug driver = Selenium::WebDriver.for:chrome driver.navigate.to "http://google.com" puts driver.find_element(:tag_name, 'input'); puts driver.find_element(:name, 'q&apos ...

What is the most effective way to transmit desktop resolution information to a website using Selenium?

I'm currently working on an application that requires me to collect data on browser window resolution and monitor resolution. The current resolution is set at 1920x1080, but I need to send 800x600 as the desktop resolution. For instance: If the des ...