The beginning of the CSS Selector is wrong.

Searching for .freesim-text-last button span you will find two elements.

Pick the one which you're trying to reach using the follow:

.freesim-text-last button span:nth-of-type(1)

for the first element and

.freesim-text-last button span:nth-of-type(2)

for the second element.

Answer from João Farias on Stack Exchange
🌐
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...
Discussions

button - click() on css Selector not working in Selenium webdriver - Stack Overflow
HTML I don't have an id or name for this . Hence am writing FirefoxDriver driver = new FirefoxDriver(); d... More on stackoverflow.com
🌐 stackoverflow.com
python - Selenium can't find xpath or css selector - Stack Overflow
I'm trying to scrape this site that has pagination. The problem I'm facing is having selenium locate the next button. What I've tried: next_button = driver.find_element_by_css_selector( 'ul[cla... More on stackoverflow.com
🌐 stackoverflow.com
java - CSS Locator with contains() InvalidSelectorException using Selenium WebDriver - Stack Overflow
Well that is the point I wanted to confirm. I was trying the locators from the IDE and the one I used was not working. BTW, I picked up the list from saucelabs.com/resources/selenium/css-selectors (Inner Text) and thought they were applicable for webdriver scripting as well. More on stackoverflow.com
🌐 stackoverflow.com
CSS selector :contains doesn't work with Selenium 2.0a7
Originally reported on Google Code with ID 987 What steps will reproduce the problem? 1. just try to retrieve element by css locator and use :contains selector. Java example: WebDriver driver = new... More on github.com
🌐 github.com
9
March 2, 2016
🌐
Stack Overflow
stackoverflow.com › questions › 50175851 › selenium-webdriver-cssselector-not-working
java - Selenium + WebDriver cssSelector not working - Stack Overflow
May 4, 2018 - Possible duplicate of NoSuchElementExeption, selenium unable to locate element ... Is this in an IFRAME? Your locator looks fine for the HTML you've posted. If you could post a link to the site, we could more easily figure it out. ... WebDriverWait wait = new WebDriverWait(driver, 10); WebElement edit_button = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button#disablerun.btn.btn-primary"))); edit_button.click();
🌐
BrowserStack
browserstack.com › home › guide › mastering selenium css selectors in 2026
CSS Selector in Selenium: Locate Elements with Examples | BrowserStack
December 10, 2025 - I realized the issue wasn’t Selenium—it was that I wasn’t picking the right selectors for the right elements. Learning how CSS selectors actually work—and when to use each type—is what finally made my tests stable, readable, and far easier to maintain.
🌐
Reflect
reflect.run › articles › fixing-invalidselectorexception-in-selenium
How to fix an InvalidSelectorException in Selenium | Reflect
The other common reason for hitting an InvalidSelectorException is that you’re using a feature of CSS or XPath that’s not supported by the underlying browser engine, and thus not supported by Selenium WebDriver. This is a more common problem with XPath selectors than CSS selectors. Since modern browsers only support the XPath 1.0 spec, which was released over twenty years ago, there are many XPath features that can be found online but which will never work in a web browser.
Find elsewhere
🌐
Software Testing Help
softwaretestinghelp.com › home › selenium automation › selenium – css selector for identifying web elements
Selenium - CSS Selector for Identifying Web Elements
May 9, 2025 - Locate/inspect the web element (“Email” textbox in our case) and notice that the HTML tag is “input” and the value of the ID attribute is “Email” and both of them collectively refer to the “Email Textbox”. Hence, the above data would create a CSS Selector. ... Type “css=input#Email” i.e. the locator value in the target box in the Selenium IDE and click on the Find button.
🌐
DevQA
devqa.io › selenium-css-selectors
Selenium CSS Selectors Examples
This tutorial provides examples of how to locate web elements in Selenium using CSS selectors. Let’s imagine we have a tag with the following attributes [id, class, name, value] <input type="text" id="fistname" name="first_name" class="myForm"> The generic way to locate elements by attribute is: css = element_name[<attribute_name>='<value>'] Example: WebElement firstName = driver.findElement(By.cssSelector("input[name='first_name']")); In CSS, we can use # notation to select the id attribute of an element: Example: driver.findElement(By.cssSelector("input#firstname")); //or driver.findElement(By.cssSelector("#firstname")); The same principle can be used to locate elements by their class attribute.
🌐
GitHub
github.com › seleniumhq › selenium-google-code-issue-archive › issues › 987
CSS selector :contains doesn't work with Selenium 2.0a7 · Issue #987 · SeleniumHQ/selenium-google-code-issue-archive
March 2, 2016 - Originally reported on Google Code with ID 987 What steps will reproduce the problem? 1. just try to retrieve element by css locator and use :contains selector. Java example: WebDriver driver = new FirefoxDriver(); driver.get("http://loc...
Author   lukeis
🌐
TOOLSQA
toolsqa.com › selenium-webdriver › css-selectors-in-selenium
How to use and create CSS Selectors in Selenium with examples?
Sometimes choosing a generic CSS Selector may point to several different elements. If this happens, Selenium will always recognize the first element pointed by the CSS locator. Hence the automation script will fail if it's not the required element.
🌐
Edureka Community
edureka.co › home › community › categories › python › why is selenium css and xpath selector not...
Why is selenium css and xpath selector not working | Edureka Community
July 18, 2019 - selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified
🌐
Reddit
reddit.com › r/learnpython › unable to use css selector in selenium
r/learnpython on Reddit: Unable to use CSS Selector in Selenium
July 14, 2020 -

I'm following the Automate The Boring Stuff course on Udemy by u/AlSwiegart. I'm on section 13 Web Scraping - 41. Controlling the Browser with the Selenium Module. I think possibly that some of the Selenium module's input syntax/requirements have changed since the video tutorial was made.

I've downloaded the chromedriver and geckodriver and added them to PATH in Windows 10. The following works to open both browsers.

driver.get('insert URL here')

I'm trying to assign a CSS Selector to a variable. The code in the video is

elem = driver.find_element_by_css_selector('insert copied css selector path here')

This gives the following error:

Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    elem = driver.find_element_by_css_selector('.main > div:nth-child(1) > div:nth-child(3) > center:nth-child(1) > a:nth-child(1) > img:nth-child(1)')
  File "C:\Users\Gaz\AppData\Local\Programs\Python\Python38-32\lib\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 "C:\Users\Gaz\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\Gaz\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Gaz\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette

I looked on the Selenium.dev website and the code there differs slightly. So I tried:

elem = driver.find_element(By.CSS_SELECTOR, "Insert copied CSS Selector Path Here")

This gives the following error:

Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    elem = driver.find_element(By.CSS_SELECTOR, ".main > div:nth-child(1) > div:nth-child(3) > center:nth-child(1) > a:nth-child(1) > img:nth-child(1)")
NameError: name 'By' is not defined

Any help is appreciated.

🌐
Sauce Labs
saucelabs.com › home › blog › selenium tips: css selectors
Selenium Tips: CSS Selectors
April 2, 2023 - CSS in Selenium has an interesting feature of allowing partial string matches using ^=, $=, or *=. I’ll define them, then show an example of each: ... An earlier version of this article references :contains, a powerful way to match elements that had a desired inner text block. Sadly, that feature is deprecated and not supported any longer by the W3C Standard. The current · CSS Selectors level 3 standard is implemented by all major browsers; level 4 is in working draft mode.