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
February 19, 2020
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
September 16, 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)

🌐
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
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.
🌐
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 ...
Find elsewhere
🌐
Selenium
selenium.dev › documentation › webdriver › elements › finders
Finding web elements | Selenium
September 6, 2025 - To improve the performance slightly, we can use either CSS or XPath to find this element in a single command. See the Locator strategy suggestions in our Encouraged test practices section. For this example, we’ll use a CSS Selector: Move Code · Java · Python · CSharp · Ruby · JavaScript · Kotlin · WebElement fruit = driver.findElement(By.cssSelector("#fruits .tomatoes")); fruit = driver.find_element(By.CSS_SELECTOR,"#fruits .tomatoes") var fruit = driver.FindElement(By.CssSelector("#fruits .tomatoes")); driver.find_element(css: '#fruits .tomatoes') View Complete Code View on GitHub ·
🌐
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
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service as ChromeService from selenium.webdriver.common.by import By # Setup chrome driver driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install())) # Navigate to the url driver.get('/tmp/selenium/index-58.html') # Find elements by CSS Selector my_elements = driver.find_elements(By.CSS_SELECTOR, 'div.card') for element in my_elements: print(element.get_attribute("outerHTML")) # Close the driver driver.quit() <div class="card">Card 1</div> <div class="card">Card 2</div> In this Python Selenium tutorial, we learned how to find all the HTML elements that match the given CSS selector, in webpage, using Selenium.
🌐
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.
🌐
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
🌐
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.
🌐
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"
🌐
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) ...
🌐
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
February 19, 2020 -

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

🌐
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.
🌐
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_