Yes, the Locator Strategy below:

submit_button = driver.find_element_by_css_selector("input[type='submit']")

is syntactically correct. But as per the copy css selector it should have been:

submit_button = driver.find_element_by_css_selector("div > button[type='submit']")

Note: find_element_by_* commands are deprecated. Please use find_element() instead

Accordingly you can also use:

submit_button = driver.find_element(By.CSS_SELECTOR, "input[type='submit']")

As per copy css selector:

submit_button = driver.find_element(By.CSS_SELECTOR, "div > button[type='submit']")
Answer from undetected Selenium 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"
Discussions

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
Please help: selenium canโ€™t find the css selector for an element
The code is probably looking for the element before the webpage is fully downloaded. You should use a Webdriver Wait method to give the page a chance to load before it searches for the element. https://selenium-python.readthedocs.io/waits.html More on reddit.com
๐ŸŒ r/Python
4
0
September 5, 2019
When using Selenium (with Python) is it bad practice to find elements by xpath?
Xpaths are fine, just make sure you are getting unique ones and not just using whatever Chrome tells you (this might vary per website). For example //input[@id='loginButton'] is a good xpath. //div/div/input[2] is a bad xpath because it could easily be broken if something moves on the page. More on reddit.com
๐ŸŒ r/QualityAssurance
22
6
May 29, 2021
Selenium can't find the element I'm searching for
So I used Selenium to automate one of my tasks. It seems that I found everything I needed using a Chrome Extension called Element Locator. I used the find_element_by_css_selector method on all of my values and it works like a charm, except for one. More on reddit.com
๐ŸŒ r/learnpython
24
35
February 26, 2020
๐ŸŒ
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()
๐ŸŒ
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)

๐ŸŒ
Selenium
selenium.dev โ€บ documentation โ€บ webdriver โ€บ elements โ€บ finders
Finding web elements | Selenium
September 6, 2025 - from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get("https://www.google.com") driver.find_element(By.CSS_SELECTOR, '[name="q"]').send_keys("webElement") # Get attribute of current active element attr = driver.switch_to.active_element.get_attribute("title") print(attr)
๐ŸŒ
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 ...
๐ŸŒ
ScrapingBee
scrapingbee.com โ€บ webscraping-questions โ€บ selenium โ€บ how-to-find-elements-css-selector-selenium
How to find elements by CSS selector in Selenium? | ScrapingBee
find_element returns the first occurrence of the CSS selector being used, while find_elements returns all elements of the page that match the selector. Now that we've understood the difference between the two functions, let's look at some code next.
Find elsewhere
๐ŸŒ
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 ...
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-selenium-find-elements-by-css-selector
How to find Elements by CSS Selector using Selenium Python
To find HTML Elements that match the given CSS Selector using Selenium in Python, call find_elements() method, pass By.CSS_SELECTOR as the first argument, and the CSS selector string (of the HTML Elements we need to find) as the second argument.
๐ŸŒ
Readthedocs
selenium-python-test.readthedocs.io โ€บ en โ€บ latest โ€บ 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') ... ID = "id" XPATH = "xpath" LINK_TEXT = "link text" PARTIAL_LINK_TEXT = "partial link text" NAME = "name" TAG_NAME = "tag name" CLASS_NAME = "class name" CSS_SELECTOR = "css selector"
๐ŸŒ
TechBeamers
techbeamers.com โ€บ locate-elements-selenium-python
Python Selenium Locate Elements - TechBeamers
November 30, 2025 - This method allows you to locate elements by class attribute name. It will return the first element matching the input attribute. If the search fails, the method throws the NoSuchElementException.
๐ŸŒ
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) ...
๐ŸŒ
ScrapingAnt
scrapingant.com โ€บ blog โ€บ selenium-python-find-element
How to Find Elements With Selenium in Python | ScrapingAnt
July 29, 2024 - This code waits up to 10 seconds for an element with the ID "myElementId" to be present on the page (Selenium documentation). Use Multiple Locator Strategies: If one locator method fails, try alternative strategies. For instance, if finding by ID doesn't work, attempt to locate the element by XPath or CSS selector.
๐ŸŒ
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.
๐ŸŒ
Oxylabs
oxylabs.io โ€บ blog โ€บ selenium-find-element
How to Find Elements With Selenium in Python
To access elements within them using CSS selectors or XPath queries with Selenium, you must first switch to the iframe element using the Selenium driver. This step ensures your element locating methods function correctly.
๐ŸŒ
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"));
๐ŸŒ
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 5, 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

๐ŸŒ
Sauce Labs
saucelabs.com โ€บ home โ€บ blog โ€บ selenium tips: css selectors
Selenium Tips: CSS Selectors
April 2, 2023 - The WebDriver code library provides methods to do just that, such as findelement() or findelements(). These usually take a locator, which can be created by ID, XPATH Code, or Cascading Style Sheets (CSS).