First: it is only warning, not error.


In my version 3.141.0 I can use both methods

from selenium import webdriver

driver = webdriver.Chrome() # Firefox()

driver.find_elements_by_css_selector(...)
driver.find_elements_by_xpath(...)
# etc.

and

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome() # Firefox()

driver.find_elements(By.CSS_SELECTOR, ...)
driver.find_elements(By.XPATH, ...)
# etc.

but it seems they plan to remove functions find_elements_by_... in the future (in versions 4.x) and now find_elements_by_... still works but it shows warning that you should use second method find_elements(By.CSS_SELECTOR, ...).

You could use module warnings to hide these warnings but better start using only second method.


BTW:

In source code for find_elements_by_css_selector you can see it runs warning.warn(...) and next it runs find_elements(By.CSS_SELECTOR, ...)


To check what version you use

import selenium

print(selenium.__version__)
Answer from furas on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › find_element_by_css_selector-driver-method-selenium-python
find_element_by_css_selector() driver method - Selenium Python - GeeksforGeeks
July 12, 2025 - This article revolves around how ...S_SELECTOR) is discussed in this article. With this strategy, the first element with the matching CSS selector will be returned....
Discussions

Selenium WebDriver question .. find_element_by_css_selector()
If you right click the element, you can copy selector or x-path. More on reddit.com
🌐 r/learnpython
7
2
June 17, 2017
AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector'
Traceback (most recent call last): ...download.py", line 310, in download_extended_page AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector'... More on github.com
🌐 github.com
4
November 12, 2022
webdriver - I need to find an element in Selenium by CSS - Stack Overflow
Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... New site design and philosophy for Stack Overflow: Starting February 24, 2026... 1 Selenium + Java = How to click on a button related to an specific span class? 5 Appium: An element could not be located using Xpath in android hybrid apps? 4 How can I select a link text using a css selector... More on stackoverflow.com
🌐 stackoverflow.com
finding items with selenium by CSS selector using multiple attributes
Your CSS selector is wrong - there shouldn't be a space between the img and the [src]. A space between items in a CSS selector means 'descendant of', so img[src] means an image with a src, but img [src] means an image with a descendant element which has a source. There probably aren't any of those on your page, so you're getting an error. In the future you can check whether your issue is with Selenium or with your CSS selector by trying out a Document.querySelector() call in your browser console to see if you can find the element with the selector you've written! More on reddit.com
🌐 r/learnpython
2
2
March 23, 2023
🌐
Bright Data
brightdata.com › faqs › selenium › find-elements-by-css
How to Find Elements by CSS Selector in Selenium?
July 10, 2024 - To find an element, we use the find_element_by_css_selector method, passing a CSS Selector string 'div.content > p.intro'. This selector targets a <p> element with the class intro inside a <div> with the class content.
🌐
Selenium Python
selenium-python.readthedocs.io › locating-elements.html
4. Locating Elements — Selenium Python Bindings 2 documentation
from selenium.webdriver.common.by import By driver.find_element(By.XPATH, '//button[text()="Some text"]') driver.find_elements(By.XPATH, '//button') The attributes available for the By class are used to locate elements on a page. These are the attributes available for By class: ID = "id" NAME = "name" XPATH = "xpath" LINK_TEXT = "link text" PARTIAL_LINK_TEXT = "partial link text" TAG_NAME = "tag name" CLASS_NAME = "class name" CSS_SELECTOR = "css selector"
🌐
LinkedIn
linkedin.com › pulse › using-css-selectors-selenium-webdriver-abhishek-garg-
Using CSS Selectors in Selenium WebDriver
February 10, 2023 - There are several ways to use CSS selectors in Selenium, but the most common method is to use the find_element_by_css_selector() method. This method accepts a CSS selector string as an argument, and returns the first matching element on the web page.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › selenium webdriver question .. find_element_by_css_selector()
r/learnpython on Reddit: Selenium WebDriver question .. find_element_by_css_selector()
June 17, 2017 -

What do I put in the HELP part below? I'm having a hard time figuring out how to use CSS Selectors with Web Driver. Below is a screenshot and the website I'm trying to work with.

http://imgur.com/a/1pJhc http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml

from selenium import webdriver

driver = webdriver.Chrome('PATH')
soup_article_links = driver.find_element_by_css_selector('HELP')
🌐
Selenium
selenium.dev › blog › 2022 › python-locators-se4
Locate your locators - Python bindings changes upcoming | Selenium
August 9, 2022 - driver.find_element_by_id("submit_button").click() driver.find_element_by_css_selectors('.myelement child').text · becomes · driver.find_element(By.ID, "submit_button").click() driver.find_element(By.CSS_SELECTOR, '.myelement child').text · If you’re really desperate however you can use strings instead of the By object: driver.find_element('id', "submit_button").click() driver.find_element('css selector', '.myelement child').text ·
🌐
GitHub
github.com › hardikvasa › google-images-download › issues › 371
AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector' · Issue #371 · hardikvasa/google-images-download
November 12, 2022 - Traceback (most recent call last): ...download.py", line 310, in download_extended_page AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector'...
Author   ZhouMingjie-code
🌐
BrowserStack
browserstack.com › home › guide › mastering selenium css selectors in 2026
CSS Selector in Selenium: Locate Elements with Examples | BrowserStack
December 10, 2025 - Matching a substring (contains: *): Locate the web element by matching the substring. ... The complete String here is “Navbar_logo__26S5Y” therefore only a substring of the String i.e: “logo_ ” is considered to locate the element. ... Mastering these CSS selector types helps you target elements more reliably, but real applications often behave differently across browsers and devices.
Top answer
1 of 3
79

Only using class names is not sufficient in your case.

  • By.cssSelector(".ban") has 15 matching nodes
  • By.cssSelector(".hot") has 11 matching nodes
  • By.cssSelector(".ban.hot") has 5 matching nodes

Therefore you need more restrictions to narrow it down. Option 1 and 2 below are available for CSS selector, 1 might be the one that suits your needs best.

Option 1: Using list items' index (CssSelector or XPath)

Limitations

  • Not stable enough if the site's structure changes

Example:

driver.FindElement(By.CssSelector("#rightbar > .menu > li:nth-of-type(3) > h5"));
driver.FindElement(By.XPath("//*[@id='rightbar']/ul/li[3]/h5"));

Option 2: Using Selenium's FindElements, then index them. (CssSelector or XPath)

Limitations

  • Not stable enough if a site's structure changes
  • Not the native selector's way

Example:

// Note that By.CssSelector(".ban.hot") and //*[contains(@class, 'ban hot')] are different, but doesn't matter in your case
IList<IWebElement> hotBanners = driver.FindElements(By.CssSelector(".ban.hot"));
IWebElement banUsStates = hotBanners[3];

Option 3: Using text (XPath only)

Limitations

  • Not for multilanguage sites
  • Only for XPath, not for Selenium's CssSelector

Example:

driver.FindElement(By.XPath("//h5[contains(@class, 'ban hot') and text() = 'us states']"));

Option 4: Index the grouped selector (XPath only)

Limitations

  • Not stable enough if the site's structure changes
  • Only for XPath, not CssSelector

Example:

driver.FindElement(By.XPath("(//h5[contains(@class, 'ban hot')])[3]"));

Option 5: Find the hidden list items link by href, then traverse back to h5 (XPath only)

Limitations

  • Only for XPath, not CssSelector
  • Low performance
  • Tricky XPath

Example:

driver.FindElement(By.XPath(".//li[.//ul/li/a[contains(@href, 'geo.craigslist.org/iso/us/al')]]/h5"));
2 of 3
0

By.cssSelector(".ban") or By.cssSelector(".hot") or By.cssSelector(".ban.hot") should all select it unless there is another element that has those classes.

In CSS, .name means find an element that has a class with name. .foo.bar.baz means to find an element that has all of those classes (in the same element).

However, each of those selectors will select only the first element that matches it on the page. If you need something more specific, please post the HTML of the other elements that have those classes.

🌐
AddSearch
addsearch.com › home › identifying css selectors
Identifying CSS Selectors - AddSearch
May 5, 2025 - The corresponding HTML element for the price will be automatically highlighted. Google Chrome displays the CSS selector at the bottom of the Developer Tools panel. You can also find the selector on the page by hovering ...
🌐
TOOLSQA
toolsqa.com › selenium-webdriver › css-selectors-in-selenium
How to use and create CSS Selectors in Selenium with examples?
Similarly, this can be extended to the sub child also by adding another “> ” followed by another locator. Similar to the child and sub-child, we can also use a CSS Selector to select the nth-child of an HTML tag. It is quite useful in recognizing list elements or in scenarios where a parent has multiple child elements with non-consistent attributes. ... Selecting nth-child using CSS Selector, for this, we will be using the following site link: https://www.demoqa.com/select-menu. Let’s take the above example; we will try to find the CSS Selector for the child element of “ul ” HTML tag, i.e.
🌐
Selenium
selenium.dev › documentation › webdriver › elements › locators
Locator strategies | Selenium
February 16, 2026 - val driver = ChromeDriver() val loc: WebElement = driver.findElement(By.className("information")) CSS is the language used to style HTML pages. We can use css selector locator strategy to identify the element on the page. If the element has ...
🌐
W3Schools
w3schools.com › cssref › css_selectors.php
CSS Selectors Reference
CSS selectors are used to "find" (or select) the HTML elements you want to style.
🌐
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 - Now that we have a basic understanding of CSS selectors, let's apply this new knowledge. The code example below finds all tag elements on the page. from selenium import webdriver from selenium.webdriver.common.by import By #open an instance of Chrome driver = webdriver.Chrome() #navigate to the page driver.get("https://quotes.toscrape.com") #look for custom elements named "tag" selector = ".tag" #find all elements with this selector elements = driver.find_elements(By.CSS_SELECTOR, selector) #print the text of each element for element in elements: print(element.text) #close the browser driver.quit()
🌐
Repeato
repeato.app › home › using css selectors to locate elements by exact text
Using CSS Selectors to Locate Elements by Exact Text - Repeato
July 16, 2024 - element = driver.find_element(By.LINK_TEXT, "Log Out") This method directly locates the link with the text “Log Out” without needing complex selectors.
🌐
Medium
medium.com › @asmirysanchezp › how-to-find-elements-using-css-selectors-c358f99fb805
How to find elements using CSS Selectors | by Asmiry Sanchez | Medium
August 24, 2020 - To find the element, right-click on the element and then click on the Inspect option: By clicking on Inspect, a tab will open where it will show us the details of all the elements.
🌐
TutorialsPoint
tutorialspoint.com › beautiful_soup › beautiful_soup_find_element_using_css_selectors.htm
Beautiful Soup - Find Element using CSS Selectors
However, the find*() methods search for the PageElements according to the Tag name and its attributes, the select() method searches the document tree for the given CSS selector. Beautiful Soup also has select_one() method. Difference in select() and select_one() is that, select() returns a ResultSet of all the elements belonging to the PageElement and characterized by the CSS selector; whereas select_one() returns the first occurrence of the element satisfying the CSS selector based selection criteria.