Simple input[name=Sex][value=M] would do pretty nice. And it's actually well-described in the standard doc:

Multiple attribute selectors can be used to refer to several attributes of an element, or even several times to the same attribute.

Here, the selector matches all SPAN elements whose "hello" attribute has exactly the value "Cleveland" and whose "goodbye" attribute has exactly the value "Columbus":

span[hello="Cleveland"][goodbye="Columbus"] { color: blue; }

As a side note, using quotation marks around an attribute value is required only if this value is not a valid identifier.

JSFiddle Demo

Answer from raina77ow on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › finding items with selenium by css selector using multiple attributes
r/learnpython on Reddit: finding items with selenium by CSS selector using multiple attributes
March 23, 2023 -

Hi all. I'm trying to use Selenium to find an element by CSS selector and although I've tried using the documentation, I think I'm misunderstanding something.

This is what I'm trying:

driver.find_element(By.CSS_SELECTOR,f"img [src='images/icons/new.gif'][alt='Add new item to list']").click()

This is the element I want to find and click:

<img src="images/icons/new.gif" alt="Add new item to list">

The error I get is as follows:

Exception has occurred: NoSuchElementException
Message: no such element: Unable to locate element: {"method":"css selector","selector":"img [src='images/icons/new.gif'][alt='Add new item to list']"}

I can see it's on the page, however, so I'm not sure what I'm missing. I can find other items using XPATH and ID so selenium is up and running, just to rule that out. Can anybody suggest anything?

(I'm using selenium 4.8.2 and python 3.11.1, if that helps)

Discussions

How to find_elements with multiple attributes using cssSelector Python and Selenium - Stack Overflow
I'm trying to find all the elements that have inside the Here is the HTML code: More on stackoverflow.com
🌐 stackoverflow.com
java - How to select an element with multiple CSS attributes using Selenium Webdriver - Stack Overflow
Ok so I did my research for sure but couldn't find an answer to my problem. Using Selenium Webdriver and on the webpage there are a list of items below is a sample HTML More on stackoverflow.com
🌐 stackoverflow.com
java - How do I use a combination of attributes to select a button in Selenium? - Software Quality Assurance & Testing Stack Exchange
I'm trying to get selenium to select a simple button that says next. I've tried XPath, CSS, and linktext and it still will not select it for me saying it cannot locate the element. Here is the code. More on sqa.stackexchange.com
🌐 sqa.stackexchange.com
November 4, 2016
how to target html nested elements ?
Xpath axes driver.findElements() More on reddit.com
🌐 r/selenium
3
4
November 5, 2022
🌐
BrowserStack
browserstack.com › home › guide › mastering selenium css selectors in 2026
CSS Selector in Selenium: Locate Elements with Examples | BrowserStack
December 10, 2025 - Selenium uses CSS selector expressions to match elements in the DOM. They allow precise targeting based on attributes, hierarchy, or partial matches.
🌐
Softwaretestingmentor
softwaretestingmentor.com › home › selenium css selector #3 – css selector with multiple attributes
Selenium CSS Selector #3 - CSS Selector with Multiple Attributes - Software Testing Mentor
September 27, 2021 - In this Selenium CSS selector tutorial we will learn how to write Selenium CSS selector using multiple attributes of the webelement. You can write advanced
🌐
RCV Academy
rcvacademy.com › home › automation testing › selenium css-selector tutorial › selenium css selector #3 – css selector with multiple attributes
Selenium CSS Selector #3 – CSS Selector with Multiple Attributes - RCV Academy
September 15, 2021 - In this Selenium CSS selector tutorial we will learn how to write Selenium CSS selector using multiple attributes of the webelement. You can write advanced CSS selectors using the mix of Tag, ID or CLASSNAME and other attributes of the webelement. Syntax for CSS selector with multiple attributes: ...
🌐
TOOLSQA
toolsqa.com › selenium-webdriver › css-selectors-in-selenium
How to use and create CSS Selectors in Selenium with examples?
Subsequently, we can use them together to create a CSS Selector for locating the web element, as shown below: textarea.form-control[placeholder='Current Address'] ... Then we provided the value of the class attribute. In the end, inside the square bracket, we provided the placeholder attribute and its value. So this way, we can combine various attributes of an HTML element to locate the web element in Selenium uniquely. With the ever-growing new technologies of web development, multiple ...
🌐
Bird Eats Bug
birdeatsbug.com › blog › css-selectors-in-selenium
CSS Selectors in Selenium: Examples and Best Practices | Bug Tracking Blog @ Bird Eats Bug
Grouping simplifies scripts and ... when multiple elements need the same action. Pseudo-classes allow selection based on position or state. Examples include :first-child, :last-child, and :nth-of-type(n). For instance, ul li:nth-of-type(2) selects the second list item in every unordered list. Pseudo-classes are valuable when elements lack unique IDs or consistent attributes, letting testers rely on structure instead. Using CSS selectors in Selenium test scripts ...
🌐
YouTube
youtube.com › software testing mentor
Selenium CSS Selector #3 - CSS Selector with Multiple Attributes - YouTube
❖ FREE Training's at https://training.rcvacademy.com ❖ In this Selenium CSS selector tutorial we will learn how to write Selenium CSS selector using multiple...
Published   April 2, 2020
Views   549
Find elsewhere
🌐
YouTube
youtube.com › natasa tech
How to use Multiple Attributes in CSS Selector Selenium | NATASA Tech - YouTube
How to use Multiple Attributes CSS SelectorIf you have many elements which is all having the same attribute and attribute value, then How to select specific...
Published   September 16, 2020
Views   292
🌐
Stack Overflow
stackoverflow.com › questions › 71270003 › how-to-find-elements-with-multiple-attributes-using-cssselector-python-and-selen › 71271653
How to find_elements with multiple attributes using cssSelector Python and Selenium - Stack Overflow
To be more canonical, you may like to consider the id attribute of the <a> element as well i.e. thumbnail. So effectively the locator strategy would be: elements = driver.find_elements(By.CSS_SELECTOR, "div#contents a#thumbnail[href]") Share · Improve this answer · Follow · edited Feb 25, 2022 at 21:21 · answered Feb 25, 2022 at 20:56 · undetected Selenium ·
🌐
YouTube
youtube.com › testing tutorialspoint
Selenium Class 26: CSS Selector with Multiple(Other Webelement) Attributes - YouTube
CSS Selector with Multiple Attributes:-------------------------------------CSS Selector using other Webelement Attributes:-----------------------------------...
Published   January 4, 2022
Views   40
🌐
RCV Academy
rcvacademy.com › home › selenium css selector multiple attributes
selenium css selector multiple attributes - RCV Academy
August 20, 2020 - In this Selenium CSS selector tutorial we will learn how to write Selenium CSS selector using multiple attributes of the webelement.
🌐
TestGrid
testgrid.io › selenium › how to use css selectors in selenium webdriver
CSS Selectors in Selenium: Types, Syntax & Examples
June 16, 2025 - Unlike other locator strategies, CSS selectors can match elements using partial attribute values (via ^=, $=, and *= operators), traverse parent-child hierarchies, and target elements by their positional index, making them the preferred choice for locating dynamic or non-unique web elements in robust, scalable Selenium test suites.
🌐
Stack Overflow
stackoverflow.com › questions › 23745823 › how-to-select-an-element-with-multiple-css-attributes-using-selenium-webdriver
java - How to select an element with multiple CSS attributes using Selenium Webdriver - Stack Overflow
0 Using selenium CSS selector for multiple things · 4 Css selector for elements with style attribute · 10 Selenium CSS selector by id AND multiple classes · 1 How to give multiple arguments to find element by css selector · 0 Multiple values in css selector with Java and selenium ·
🌐
The Test Tribe
thetesttribe.com › home › automation › css selectors in selenium explained (with examples)
CSS Selectors in Selenium Explained (with Examples) - The Test Tribe
April 2, 2025 - You can combine multiple selectors using a comma (,) to select various elements. CSS Selectors are generally faster and simpler than XPath, but XPath is more powerful for navigating complex DOM structures.
🌐
Pcloudy
pcloudy.com › home › understanding css selectors in selenium
Understanding CSS Selectors in Selenium
February 15, 2024 - In cases where multiple elements match your selector, adjust the specificity by adding or removing attribute selectors or using different combinators. Use CSS Selector Testers: Explore online CSS selector testing tools that allow you to enter ...
🌐
DevQA
devqa.io › selenium-css-selectors
Selenium CSS Selectors Examples
The same principle can be used to locate elements by their class attribute. We use the . notation. driver.findElement(By.cssSelector("input.myForm")); //or driver.findElement(By.cssSelector(".myForm"));
🌐
Testmuai
testmuai.com › testmu ai › learning hub › css selectors in selenium
CSS Selectors in Selenium: A Complete Guide to Locating Web Elements
February 3, 2026 - Use CSS wherever possible to improve test speed and maintainability. Combine Attributes for Uniqueness: If a single attribute isn’t unique, combine multiple attributes like [name='username'][type='text'] to pinpoint the element precisely.
🌐
Selenium
selenium.dev › documentation › webdriver › elements › locators
Locator strategies | Selenium
February 16, 2026 - We can use css selector locator strategy to identify the element on the page. If the element has an id, we create the locator as css = #id. Otherwise the format we follow is css =[attribute=value] . Let us see an example from above HTML snippet.