I suspect this is due to a bug in cssQuery, which Selenium currently uses to locate elements by CSS. Details of the issue and a patch can be found in the comments of the following issue: http://jira.openqa.org/browse/SEL-698

Hope that helps - I believe Selenium 2 will be using a different library for CSS locators - possibly JQuery's Sizzle (http://sizzlejs.com/), which should solve this problem.

Dave.

Answer from Dave Hunt on Stack Overflow
🌐
TOOLSQA
toolsqa.com › selenium-webdriver › css-selectors-in-selenium
How to use and create CSS Selectors in Selenium with examples?
CSS Selectors are one of the locator strategies offered by Selenium to identify the web elements. The CSS Selectors mainly use the character sequence pattern, which identifies the web elements based on their HTML structure.
People also ask

Why Use CSS Selectors in Selenium?
CSS Selectors in Selenium offer a fast, reliable, and simple way to locate web elements. They are interpreted directly by the browser, making them faster than XPath. Their clean syntax improves readability, ensures consistent results across browsers, and makes maintenance easier as web pages evolve.
🌐
testmuai.com
testmuai.com › testmu ai › learning hub › css selectors in selenium
CSS Selectors in Selenium: A Complete Guide to Locating Web Elements
How do CSS Selectors improve test script maintainability in Selenium?
CSS Selectors improve maintainability by providing shorter, cleaner locators that are easier to read and update. Since they closely match how browsers interpret elements, even small UI or DOM changes don’t break them as easily as XPath expressions. This makes long-term test maintenance smoother, especially in agile projects with frequent front-end updates.
🌐
testmuai.com
testmuai.com › testmu ai › learning hub › css selectors in selenium
CSS Selectors in Selenium: A Complete Guide to Locating Web Elements
How can you verify whether a CSS Selector correctly identifies an element before using it in Selenium?
You can validate a CSS Selector directly in your browser’s Developer Tools. Press F12 → Elements tab → Ctrl/Cmd + F, then paste the CSS Selector. If it correctly highlights the intended element, it’s valid. This step ensures accuracy and prevents script failures caused by incorrect locators.
🌐
testmuai.com
testmuai.com › testmu ai › learning hub › css selectors in selenium
CSS Selectors in Selenium: A Complete Guide to Locating Web Elements
🌐
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. Faster and cleaner than many other locator strategies (like XPath).
🌐
Selenium
selenium.dev › documentation › webdriver › elements › locators
Locator strategies | Selenium
1 month ago - Otherwise the format we follow is css =[attribute=value] . Let us see an example from above HTML snippet. We will create locator for First Name textbox, using css.
🌐
Pcloudy
pcloudy.com › home › understanding css selectors in selenium
Understanding CSS Selectors in Selenium
February 15, 2024 - CSS Selectors are used within Selenium to locate elements on a web page. They are beneficial because they are shorter than XPath locators and allow for a more clear and crisp method to locate the element.
🌐
TestGrid
testgrid.io › selenium › how to use css selectors in selenium webdriver
Mastering CSS Selectors in Selenium for efficient locators
June 16, 2025 - In the above example, if you try to locate the seleniumbase.com URL using only the class attribute, you will find four elements on the web page which has “linkClass” as class value. To uniquely identify the URL, you need to use one more attribute which is the name. The complete selector would be: ... 5. Substring selector: In Selenium, CSS selectors support partial string matching with the help of specific symbols to match the beginning (^), end ($) or any part (*) of an attribute’s value.
🌐
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 - CSS Selectors are among the most efficient ways to identify elements in Selenium because they combine speed, precision, and simplicity. Unlike XPath, which can be verbose and slow in some browsers, CSS Selectors are interpreted natively by the ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › software testing › selenium-css-selectors
Selenium CSS Selectors - GeeksforGeeks
In the context of Selenium, CSS selectors allow you to locate elements on a webpage for automation. CSS selectors are generally faster than other locators like XPath and can be more concise, making them a preferred choice for many automation testers.
Published   July 23, 2025
🌐
Edureka
edureka.co › blog › css-selectors-in-selenium
CSS Selectors in Selenium | Getting Started with CSS Selectors | Edureka
October 17, 2024 - In Selenium WebDriver, in order to interact with a web element such as a click, or type something, we need to first locate the elements. One of the most important tasks of a test automation engineer is to be able to identify different elements on the webpage. There are several element locators but, locating elements using CSS Selectors is the preferred way as it is faster than XPath.
🌐
Guru99
guru99.com › home › selenium › css selector in selenium
CSS Selector in Selenium
April 24, 2025 - CSS Selectors in Selenium are string patterns used to identify an element based on a combination of HTML tag, id, class, and attributes. Locating by CSS Selectors in Selenium is more complicated than the previous methods, but it is the most ...
🌐
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 - To use CSS Selectors in Selenium, use the By.cssSelector method provided by the WebDriver API. It helps locate elements quickly and effectively.
🌐
Testmu
testmu.ai › testmu ai › blog › 8 types of locators in selenium webdriver: examples, syntax, and best practices
Locators In Selenium WebDriver With Examples | TestMu AI (Formerly LambdaTest)
January 11, 2026 - If the web element has an ID and name, it can be located using its ID, Name, XPath, or CSS Selector. Similarly, the respective tagName or the className can locate the same WebElement.
🌐
UI Vision
ui.vision › rpa › docs › selenium-ide › locators
Locators and Selectors in Selenium IDE 2024 - Tutorial
Locator is a fancy word for how you tell Selenium IDE to find the right place to click on. We use here “click”, but the same applies for other commands that do something else with a DOM element. In other words, locators are used as input by all commands that do something at a specific place.
🌐
DevQA
devqa.io › selenium-css-selectors
Selenium CSS Selectors Examples
<input type="text" id="fistname" name="first_name" class="myForm"> The generic way to locate elements by attribute is: ... driver.findElement(By.cssSelector("input#firstname")); //or driver.findElement(By.cssSelector("#firstname"));
🌐
Medium
moniljoshi.medium.com › css-selectors-for-locating-elements-in-details-e6cbd62b99fc
Different CSS Selectors techniques for locating elements in Selenium Web Driver | by Monil Joshi | Medium
October 19, 2021 - CSS Selectors in Selenium are string patterns used to identify an element based on a combination of HTML tag, id, class, and other attributes. Identifying an element is most preferred way of locating an element in CSS as it can access even those ...
🌐
BrowserStack
browserstack.com › home › guide › locators in selenium: a detailed guide
Locators in Selenium: A Detailed Guide | BrowserStack
September 26, 2024 - Selenium provides different locator such as ID, Name, TagName, ClassName, XPath, CSS Selector, LinkText, and PartialLinkText.
🌐
Bird Eats Bug
birdeatsbug.com › blog › css-selectors-in-selenium
CSS Selectors in Selenium: Examples and Best Practices | Bug Tracking Blog @ Bird Eats Bug
CSS selectors are a key way to locate elements on a web page when automating tests with Selenium. They provide a simple and efficient method to target elements by ID, class, tag, or other attributes.
🌐
Loadero
loadero.com › blog › articles › css-selectors-and-xpath-locators-in-selenium-test-automation-scripts
CSS Selectors And XPath Locators In Selenium Test Automation Scripts - Loadero
One of the most important aspects of automated web application testing is having a good grasp of using locators. Locators allow retrieving DOM elements from the web page. Interacting with web elements during automated tests allows to create ...
🌐
ScrapeOps
scrapeops.io › home › selenium web scraping playbook › python selenium find elements css
Python Selenium Guide - Finding Elements by CSS Selectors | ScrapeOps
January 8, 2024 - Simply right-click the element and choose to copy the CSS selector: If we'd like to find just one element, we can use Selenium's find_element() method to find and return a single element.