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"
🌐
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

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: ... You might want to provide a bit more information. What language and libraries are you using? Python? JS? Java? what versions? I assume the "copy css selector" is in Chrome or some ... 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
Selenium | css-selector not found
Hi, I’m trying stuf with selenium. For some reason the selector I get isn’t found. code: #Importing libraries from selenium import webdriver import pandas as pd from selenium.webdriver.common.keys import Keys impor… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
April 1, 2021
🌐
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 - Here are some best practices that you can consider for location elements in Selenium with Python: Use Unique Identifiers as they are the most stable and reliable method for element identification. Use more precise locator strategies like CSS selectors or ID over generic methods like tag names.
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
    
🌐
Apify
blog.apify.com › python-css-selectors
Python CSS selectors and how to use them
March 21, 2024 - A short guide with examples of using CSS selectors with two popular Python libraries for web scraping: Beautiful Soup and Selenium.
🌐
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
🌐
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 - Take a look below to see this in action. from selenium import webdriver from selenium.webdriver.common.by import By from time import sleep #open Chrome driver = webdriver.Chrome() #navigate to the site driver.get("https://quotes.toscrape.com") #find the h1 element h1 = driver.find_element(By.CSS_SELECTOR, "h1") #print the h1 element print(f"H1 element: {h1.text}") #find all quotes (span elements with the class: 'text') quotes = driver.find_elements(By.CSS_SELECTOR, "span[class='text']") for quote in quotes: print(f"Quote: {quote.text}") #find all tags (anything with the class 'tag') tags = dri
Find elsewhere
🌐
ScrapingBee
scrapingbee.com › webscraping-questions › css_selectors › how-to-use-css-selectors-in-python
How to use CSS Selectors in Python? | ScrapingBee
The select() method searches for all HTML elements that match the provided CSS selector and returns them as a list of Tag objects. If no elements match, it returns an empty list. Conversely, the select_one() method searches for the first HTML ...
🌐
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_
🌐
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.
🌐
ScrapingBee
scrapingbee.com › webscraping-questions › selenium › how-to-find-elements-css-selector-selenium
How to find elements by CSS selector in Selenium? | ScrapingBee
Now that we know how to find the CSS selectors we need, let's proceed to set up Selenium and use these selectors. To get Selenium up and running, we first need to download the browser and its corresponding driver. For Chrome, we can download the browser first, and get the ChromeDriver from https://developer.chrome.com/docs/chromedriver/downloads. Next, we can install the Python ...
🌐
Sauce Labs
saucelabs.com › home › blog › selenium tips: css selectors
Selenium Tips: CSS Selectors
April 2, 2023 - Let’s write an XPath and css selector that will choose the input field after “username”. This will select the “alias” input, or will select a different element if the form is reordered. ... If you don’t care about the ordering of child elements, you can use an attribute selector in selenium to choose elements based on any attribute value.
🌐
Scrapfly
scrapfly.io › blog › answers › 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..."
🌐
BrowserStack
browserstack.com › home › guide › mastering selenium css selectors in 2026
CSS Selector in Selenium: Locate Elements with Examples | BrowserStack
December 10, 2025 - Learn to use CSS Selector in Selenium scripts for your automated tests with five types of CSS Selectors and code snippet examples.
🌐
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 - CSS Selectors are generally faster and simpler than XPath, but XPath is more powerful for navigating complex DOM structures. Selenium will return the first matching element when using findElement.
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 =

🌐
freeCodeCamp
forum.freecodecamp.org › python
Selenium | css-selector not found - Python - The freeCodeCamp Forum
April 1, 2021 - Hi, I’m trying stuf with selenium. For some reason the selector I get isn’t found. code: #Importing libraries from selenium import webdriver import pandas as pd from selenium.webdriver.common.keys import Keys import time # creating instance for web driver driver = webdriver.Chrome() driver.get("https://soundcloud.com/discover") print( driver.title) inputElement = driver.find_element_by_css_selector("#app > header > div > div.header__middle > div > form > input") inputElement.send_keys...
🌐
Python Examples
pythonexamples.org › python-selenium-find-element-by-css-selector
How to find Element by CSS Selector using Selenium Python
January 11, 2026 - 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.
🌐
Reddit
reddit.com › r/python › please help: selenium can’t find the css selector for an element
r/Python on Reddit: Please help: selenium can’t find the css selector for an element
September 8, 2019 -

Finding elements by CSS selector is the only way Al Sweigart has taught me. I've tried finding by xpath and by class name and still got an exception although idk if I did those right

here's my code, dont laugh at the website:

from selenium import webdriver

browser = webdriver.Firefox()

browser.get('https://www.barstoolsports.com/shows/call-her-daddy/ask')

elem_for_first_name = browser.find_element_by_css_selector('.quantumWizTextinputPaperinputInput')





Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/home/fakename/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 598, in find_element_by_css_selector

return self.find_element(by=By.CSS_SELECTOR, value=css_selector)

File "/home/fakename/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element

'value': value})['value']

File "/home/fakename/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute

self.error_handler.check_response(response)

File "/home/fakename/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response

raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .quantumWizTextinputPaperinputInput

I get similar exceptions when trying xpath and class name.

There are a total of 2 (maybe 3) elements I need from this webpage:

  1. element for entering your first name

  2. element for asking your question

  3. (maybe) the submit button

Number 3 might not be that hard since selenium can automatically submit a form after you send the keys. I just haven't gotten to this point yet because I cant find the first 2 elements to begin with.

Please, good pythoners of reddit, help a girl out