The main problem is at this line:

driver.findElement(By.cssSelector("a:contains('About Google')"));

css doesn't maintain contains() for Selenium WD - See here.

For using contains() you have to use Xpath.

With Xpath your locator will be:

//a[contains(text(), 'About Google')]

and for driver it will be as:

driver.findElement(By.xpath("//a[contains(text(), 'About Google')]"));

For finding links with Selenium you can use:

driver.findElement(By.linkText("your link name here"));

It is limitation of CSS selectors compare to Xpath:

  • you can't take parent element with CSS selectors (Xpath has XPath axes)
  • you can't use contains (it is only XPath privilege).

BTW
For processing Xpath locators from page you able to use extension for Firefox browser:

  • FirePath

  • Xpath Checker

Answer from catch32 on Stack Overflow
Discussions

selenium - Does CSS Selector have contains text similar to xpath? - Stack Overflow
In Selenium, are there any options for CSS selectors with "contains" similar to Xpath where we check with contains[text(),....]. In the following example, I have given the CSS and Xpath &... More on stackoverflow.com
🌐 stackoverflow.com
xpath - Selenium Python: find_element_by_css_selector() using :contains() - Stack Overflow
I had two significant mistakes: 1.) I thought that :contains() was an accepted css3 selector (turns out it is not part of the current spec, which is why i couldn't select that way) 2.) The xpath selector would have been fine except that I was using a parser that assumed xpath would never have any spaces in it, so it split the arguments by spaces. Therefore, when i passed in the xpath selector... 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
April 18, 2024
Python Selenium get element by CSS matching text - Stack Overflow
Hi I can't figure out how to get an element by CSS and matching with text. I know it can be done with Xpath but I'd rather use CSS. More on stackoverflow.com
🌐 stackoverflow.com
🌐
BrowserStack
browserstack.com › home › guide › mastering selenium css selectors in 2026
CSS Selector in Selenium: Locate Elements with Examples | BrowserStack
December 10, 2025 - 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.
🌐
QACRAFT -
qacraft.com › home › selenium testing › css selector in selenium
Css Selector in Selenium - QACRAFT
June 21, 2022 - 5) Inner Text: Utilizing inner text distinguishes and makes CSS Selectors in Selenium WebDriver by using a string design that the HTML Tag appears on the site page. This instrument is utilized most often to find web components by virtue of its improved sentence structure. Syntax: css=<HTML tag><:><contains><(text)> 1) Absolute Path CSS Selector: In this selector (>) sign is used to reach til element.
🌐
SWTestAcademy
swtestacademy.com › home › css selectors in selenium 17 tactics and examples
CSS Selectors in Selenium 17 Tactics and Examples
January 1, 2022 - (Note: For XPath we use tag[contains((@attribute,’containing text’)] for this.) ... You can use tag[attribute^=’starting text’] syntax. (Note: For XPath we use tag[starts-with( @attribute, ‘starting text’)] for this.) ... You can use tag[attribute$=’ending text’] syntax. ... You can use “,” operator between two CSS locator statements.
🌐
TestGrid
testgrid.io › selenium › how to use css selectors in selenium webdriver
Mastering CSS Selectors in Selenium for efficient locators
June 16, 2025 - In the above example, Pre-filled text field has a value of “Text…”. If the value is dynamic but you are sure that it always ends with “…”, you can use a CSS selector that like below: ... c. Matching a substring (contains: *): To locate a web element using the substring that appears anywhere in the attribute value.
Find elsewhere
🌐
QAFox
qafox.com › home › selenium locators - using starts with, ends with and contains in css selectors
Selenium Locators – Using starts with, ends with and contains in CSS Selectors - QAFox
July 18, 2019 - The main purpose of using starts with (^), ends with ($) and contains (*) in CSS Selector is to locate the UI elements having the attribute values text which is dynamically changing at the beginning, middle or end.
🌐
Packtpub
subscription.packtpub.com › book › programming › 9781849515740 › 1 › ch01lvl1sec16 › locating-elements-using-text
Locating Elements | Selenium Testing Tools Cookbook
The contains()pseudo-class accepts the text to be searched as a parameter. It then checks all the <td> elements in DOM for the specified text. The contains() pseudo-class may not work with browsers that don't natively support CSS selectors.
🌐
TOOLSQA
toolsqa.com › selenium-webdriver › css-selectors-in-selenium
How to use and create CSS Selectors in Selenium with examples?
The Symbol for representing the contains the text: ‘’* Using the same symbol in CSS Selector, the expression for the above elements will be: ... Here, we have used the middle characters of the id attribute value, i.e., “username” from the HTML to locate the element. Note: Always make sure that your CSS expression points to a unique element. 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.
🌐
Sauce Labs
saucelabs.com › home › blog › selenium tips: css selectors
Selenium Tips: CSS Selectors
April 2, 2023 - CSS in Selenium has an interesting ... An earlier version of this article references :contains, a powerful way to match elements that had a desired inner text block....
🌐
DevQA
devqa.io › selenium-css-selectors
Selenium CSS Selectors Examples
To locate the element with text ‘Orange’, we have to use nth-of-type. ... Likewise, to select the last child element, i.e. ‘Banana’, we use: driver.findElement(By.cssSelector("ul#fruit li:last-child")); We can use string matchers to locate elements with dynamically generated Ids. In this example, all the three div elements contain the word ‘random’.
🌐
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
April 18, 2024 - 1. just try to retrieve element by css locator and use :contains selector. Java example: WebDriver driver = new FirefoxDriver(); driver.get("http://localhost:8080/"); WebElement webElement = driver.findElement(By.cssSelector("a:contains('Text')")); With FirefoxDriver it throws: org.openqa.selenium.WebDriverException: An invalid or illegal string was specified with HtmlUnitDriver it throws: com.steadystate.css.sac.TestCSSParseException: Error in pseudo class or element.
Author   lukeis
🌐
Google Groups
groups.google.com › g › selenium-users › c › SEMa-ytXgYs
Text in CSS selector
May 26, 2023 - We can't do that. We cannot identify elements using text in the CSS selector. To do that, you'll have to use an XPath. Thanks & Regards Raj Kumar Mobile: - +1 6026934946 ... -- You received this message because you are subscribed to the Google Groups "Selenium Users" group.
🌐
Guru99
guru99.com › home › selenium › css selector in selenium
CSS Selector in Selenium
April 24, 2025 - Selenium IDE should be able to access the Password label as shown in the image below. Step 3) This time, replace the inner text with “Boston” so that your Target will now become “css=font:contains(“Boston”)”. Click Find. You should notice that the “Boston to San Francisco” label becomes highlighted.
🌐
TutorialsArena
tutorialsarena.com › fundamentals › selenium › selenium-css-selector-inner-text
CSS Selectors: Using the :contains() Pseudo-class for Text-Based Element Selection
August 10, 2024 - This selects any element of the specified element type that contains the exact text string provided within the contains() pseudo-class. Note that this selector is not part of standard CSS and might not be supported in all browsers or testing ...
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-an-element-that-contains-specific-text-in-python-selenium
Find an element that Contains Specific Text in Python Selenium - GeeksforGeeks
July 23, 2025 - This is especially useful when we need to verify that certain text is displayed on a page or interact with elements based on the text they contain. While Selenium provides multiple ways to locate elements, the most effective methods for finding elements by their text are using XPath or CSS selectors.