As you've mentioned

The class name has spaces in it, which lead me to use the css_selector

this is right approach, however you should also make sure that one

  1. One should remove the space and put a .
  2. . represent class in CSS.

So the below code should work:

driver.find_element(By.CSS_SELECTOR, ".btn.btn-alt.see-full-list-btn")

or you can even use it with the tag a

driver.find_element(By.CSS_SELECTOR, "a.btn.btn-alt.see-full-list-btn")

or the recommended solution would be to use with explicit waits:

see_full_list_button = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a.btn.btn-alt.see-full-list-btn")))
see_full_list_button.click()

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Answer from cruisepandey on Stack Overflow
๐ŸŒ
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"
๐ŸŒ
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 - This section is devoted to showing off the flexibility of CSS selectors. There are code examples to find all sorts of elements on a page using different CSS criteria. The ID attribute provides a unique identifier for an HTML element, making it a reliable and direct way to locate specific elements on a webpage. As we have done previous examples, we can find an element by its ID using the # character. from selenium import webdriver from selenium.webdriver.common.by import By #open Chrome driver = webdriver.Chrome() #navigate to the site driver.get("https://quotes.toscrape.com/login") #find the username by ID username = driver.find_element(By.CSS_SELECTOR, "#username") #type stuff in the box username.send_keys("some text") #close the browser driver.quit()
Discussions

Css Selector button click with selenium (python) - Stack Overflow
I am trying to click on a button using selenium. My code states it is unable to find the css_selector with said class name. The class name has spaces in it, which lead me to use the css_selector ob... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - How to located selenium element by css selector - Stack Overflow
I want to locate an element in selenium using css selector, and I use the program "copy css selector" and got: div>button[type ="submit"] Is this correct? submit_button = dr... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Selenium / Python - Selecting via css selector - Stack Overflow
Issue: Can not select from css selector specific element. Need to verify that the registered user can change their password successfully. I have tried the different attributes of the class to cal... More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 22, 2017
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
๐ŸŒ
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)

Top answer
1 of 2
2

As you've mentioned

The class name has spaces in it, which lead me to use the css_selector

this is right approach, however you should also make sure that one

  1. One should remove the space and put a .
  2. . represent class in CSS.

So the below code should work:

driver.find_element(By.CSS_SELECTOR, ".btn.btn-alt.see-full-list-btn")

or you can even use it with the tag a

driver.find_element(By.CSS_SELECTOR, "a.btn.btn-alt.see-full-list-btn")

or the recommended solution would be to use with explicit waits:

see_full_list_button = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a.btn.btn-alt.see-full-list-btn")))
see_full_list_button.click()

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
2 of 2
0

There is no necessity to focus on the element HTML after the click is already invoked.

As per the HTML

<a href="#" class="btn btn-alt see-full-list-btn">See Full List</a>

you can use either of the following locator strategies:

  • Using link_text:

    driver.find_element(By.LINK_TEXT, "See Full List").click()
    
  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "a.btn.btn-alt.see-full-list-btn").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//a[@class='btn btn-alt see-full-list-btn' and text()='See Full List']").click()
    

Ideally to click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "See Full List"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-alt.see-full-list-btn"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn btn-alt see-full-list-btn' and text()='See Full List']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-selenium-find-element-by-css-selector
How to find Element by CSS Selector using Selenium Python
To find an HTML Element by CSS Selector using Selenium in Python, call find_element() method and pass By.CSS_SELECTOR as the first argument, and the CSS selector string (of the HTML Element we need to find) as the second argument.
๐ŸŒ
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 - Create a file called run.py to demonstrate find_element_by_css_selector method - ... # Python program to demonstrate # selenium # import webdriver from selenium import webdriver from selenium.webdriver.common.by import By # create webdriver object driver = webdriver.Firefox() # enter keyword to search keyword = "geeksforgeeks" # get geeksforgeeks.org driver.get("https://www.geeksforgeeks.org/") # get element element = driver.find_element(By.CSS_SELECTOR, "input.gsc-i-id2") # print complete element print(element)
Find elsewhere
Top answer
1 of 2
34
driver.find_element_by_css_selector(".test_button4[value='Update']").click()

EDIT: Because the selector needs a class, id, or tagname, but value.Update by itself is none of these.

.test_button4 provides a classname to match against, and from there, [value='Update'] specifies which particular match(es) to select.

2 of 2
3
test_button4 = driver.find_elements_by_class_name('test_button4') # notice its "find_elementS" with an S
submit_element = [x for x in test_button4 if x.get_attribute('value') == 'Update'] #this would work if you had unlimited things with class_name == 'test_button4', as long as only ONE of them is value="Update"
if len(submit_element): # using a non-empty list as truthiness
    print ("yay! found updated!")

This is something that i hardly ever see anyone document, explain, or use.

(ill use name for example because its simplest)

find_element_by_name() returns a single item, or gives an exception if it doesnt find it

find_elements_by_name() returns a list of elements. if no elements found, the list is empty

so if you do a find_elements_by_class_name() and it returns a list with X entries in it, all thats left at that point to narrow down what you want is either some old fashioned list comprehension ( like how i used in my answer ) or some indexing if you for some reason know which element you want.

also get_attribute() is seriously under-utilized as well. it parses the inside of the elements html by using what is before the = and returns what is after the =

๐ŸŒ
YouTube
youtube.com โ€บ software testing mentor
Selenium Python Tutorial #16 - How to Find Element By CSS Selector - YouTube
Get all my courses for USD 5.99/Month - https://bit.ly/all-courses-subscriptionIn this Selenium Python Tutorial, we will learn how to find Element by CSS Sel...
Published ย  April 14, 2021
Views ย  28K
๐ŸŒ
ScrapingBee
scrapingbee.com โ€บ webscraping-questions โ€บ selenium โ€บ how-to-find-elements-css-selector-selenium
How to find elements by CSS selector in Selenium? | ScrapingBee
Next, we can install the Python bindings for Selenium using pip, uv, or any other package management system: ... You can find elements by CSS selectors in Selenium by utilizing the find_element and find_elements methods.
๐ŸŒ
Sauce Labs
saucelabs.com โ€บ home โ€บ blog โ€บ selenium tips: css selectors
Selenium Tips: CSS Selectors
April 2, 2023 - Useful Selenium tips on CSS rules and pseudo-classes that will help you understand how to convert your XPATH locators to CSS, a native approach on all browsers.
๐ŸŒ
BrowserStack
browserstack.com โ€บ home โ€บ guide โ€บ mastering selenium css selectors in 2026
CSS Selector in Selenium: Locate Elements with Examples | BrowserStack
December 10, 2025 - To make it unique we should also use the โ€œhrefโ€ attribute. ... CSS Selectors in Selenium allows to match a partial String with the help of various symbols to represent the start, end and contents inside a text.
๐ŸŒ
BrowserStack
browserstack.com โ€บ home โ€บ guide โ€บ how to find elements in selenium with python: id, xpath, css, and more
Find Elements in Selenium with Python: ID, XPath, CSS, & More | BrowserStack
January 28, 2025 - Read More: CSS Selector in Selenium: Locate Elements with Examples ยท Here is the method to find elements in Selenium with Python using Link Text and Partial Link Text: # With the help of exact text link = driver.find_element(By.LINK_TEXT, "Help Center") # With the help of partial text partial_link ...
๐ŸŒ
Apify
blog.apify.com โ€บ python-css-selectors
Python CSS selectors and how to use them
March 21, 2024 - In these examples, By.CSS_SELECTOR is used with appropriate CSS selector strings: h2 selects elements by tag name (just as By.TAG_NAME, 'h2' does), and .product selects elements by class name (similar to By.CLASS_NAME, 'product'), with the dot (.) prefix indicating a class name in CSS selector syntax. While Beautiful Soup supports a wide range of CSS selectors for parsing HTML documents, the categorization and naming can vary slightly compared to Selenium WebDriver.
๐ŸŒ
ScrapingBee
scrapingbee.com โ€บ webscraping-questions โ€บ css_selectors โ€บ how-to-use-css-selectors-in-python
How to use CSS Selectors in Python? | ScrapingBee
Alternatively, you can use CSS selectors in Selenium to do the same thing. Here is some sample code: from selenium import webdriver from selenium.webdriver.common.by import By DRIVER_PATH = '/path/to/chromedriver' driver = webdriver.Chrome(executable_path=DRIVER_PATH) # Open Scrapingbee's website driver.get("http://www.scrapingbee.com") # Get the first h1 element using find_element h1 = driver.find_element(By.CSS_SELECTOR, "h1") print(h1.text) # Output: 'Tired of getting blocked while scraping the web?'
๐ŸŒ
Linux Hint
linuxhint.com โ€บ locating_elements_css
Locating Elements by CSS Selectors with Selenium
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
๐ŸŒ
Selenium
selenium.dev โ€บ documentation โ€บ webdriver โ€บ elements โ€บ locators
Locator strategies | Selenium
February 16, 2026 - import pytest from selenium import webdriver from selenium.webdriver.common.by import By def test_class_name(): driver = webdriver.Chrome() driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html") element = driver.find_element(By.CLASS_NAME, "information") assert element is not None assert element.tag_name == "input" driver.quit() def test_css_selector(driver): driver = webdriver.Chrome() driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html") element = driver.find_element(By.CSS_SELECTOR, "#fname") assert element is not None assert element.get_
๐ŸŒ
Scrapfly
scrapfly.io โ€บ blog โ€บ how-to-find-elements-by-css-selectors-in-selenium
How to find elements by CSS selector in Selenium
May 29, 2023 - from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get("https://httpbin.dev/html") element = driver.find_element(By.CSS_SELECTOR, 'p') # then we can get the element text print(element.text) "Availing himself of the mild, summer-cool weather that now reigned in these latitudes..."
๐ŸŒ
DevQA
devqa.io โ€บ selenium-css-selectors
Selenium CSS Selectors Examples
driver.findElement(By.cssSelector("ul#fruit li:last-child"));