Replace find_element_by_xpath_selector with find_element_by_xpath (There is no find_element_by_xpath_selector method):

driver = webdriver.Firefox()
...
driver = driver.find_element_by_xpath(u"//td[contains(text(), 'hello')]")

COMPLETE EXAMPLE

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('http://python.org')
link = driver.find_element_by_xpath(u'//a[contains(text(), "Download")]')
link.click()
Answer from falsetru on Stack Overflow
🌐
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.
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
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
selenium - A way to match on text using CSS locators - Software Quality Assurance & Testing Stack Exchange
1 CSS Selector using ':contains' fails with `invalid element state: Failed to execute 'querySelector' on 'Document: is not a valid selector'` 12 Is jQuery faster than CSS/Xpath selectors for IE 8.0 in Selenium1? More on sqa.stackexchange.com
🌐 sqa.stackexchange.com
Selenium + Python: Print text of an element located by CssSelector - Stack Overflow
I am new to Selenium and Python. I would like to navigate through a website, find an element and print it (or store it in a csv file). Python version: 3.10; Selenium Webdriver: Firefox; IDE: PyChar... More on stackoverflow.com
🌐 stackoverflow.com
May 9, 2025
People also ask

Why Use CSS Selectors in Selenium?
CSS Selectors in Selenium offer a fast, reliable, and simple way to locate web elements. They are interpreted directly by the browser, making them faster than XPath. Their clean syntax improves readability, ensures consistent results across browsers, and makes maintenance easier as web pages evolve.
🌐
testmu.ai
testmu.ai › testmu ai › learning hub › css selectors in selenium
CSS Selectors in Selenium: A Complete Guide to Locating Web Elements
Why are CSS Selectors generally faster than XPath in Selenium?
CSS Selectors execute faster because browsers natively use CSS engines to render elements. XPath, on the other hand, requires an additional parsing layer to traverse the DOM, increasing processing time. This native optimization gives CSS Selectors an advantage in test execution speed, particularly for large-scale web applications.
🌐
testmu.ai
testmu.ai › testmu ai › learning hub › css selectors in selenium
CSS Selectors in Selenium: A Complete Guide to Locating Web Elements
How can you verify whether a CSS Selector correctly identifies an element before using it in Selenium?
You can validate a CSS Selector directly in your browser’s Developer Tools. Press F12 → Elements tab → Ctrl/Cmd + F, then paste the CSS Selector. If it correctly highlights the intended element, it’s valid. This step ensures accuracy and prevents script failures caused by incorrect locators.
🌐
testmu.ai
testmu.ai › testmu ai › learning hub › css selectors in selenium
CSS Selectors in Selenium: A Complete Guide to Locating Web Elements
🌐
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"
🌐
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.
Find elsewhere
🌐
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.
🌐
Thedigitalgroup
blog.thedigitalgroup.com › locator-strategies-in-selenium-webdriver-css-selectors
Locator Strategies in Selenium WebDriver: CSS selectors | T/DG Blog - Digital Thoughts
January 13, 2026 - This is right now not supported by WebDriver in case of CSS, but most probably will support in upcoming Selenium 3 or 4. Syntax: css= tag:contains(‘inner text’), Here in syntax we can use any combination discussed above.
🌐
BrowserStack
browserstack.com › home › guide › how to find elements by text in selenium with python
How to Find Elements by Text in Selenium with Python | BrowserStack
March 20, 2025 - Combine text() and contains() methods for more precise element location when dealing with dynamic content. Utilize tools like XPath Finder or Selenium IDE to help construct accurate XPath expressions for text-based element location.
🌐
Testmu
testmu.ai › testmu ai › learning hub › css selectors in selenium
CSS Selectors in Selenium: A Complete Guide to Locating Web Elements
January 11, 2026 - Handle Dynamic Elements Gracefully: For dynamic elements, use CSS pseudo-classes like :nth-child() or :contains() (via JavaScript execution) to locate elements based on visible order or text.
🌐
ScrapingBee
scrapingbee.com › webscraping-questions › css_selectors › how-to-select-html-elements-by-text-using-css-selectors
How to select HTML elements by text using CSS Selectors? | ScrapingBee
However, this has been deprecated for a long time and is no longer supported by the W3C standard. If you want to select an element by text, you should look into other options. Most Python libraries provide a way for you to do so.
🌐
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....
🌐
SWTestAcademy
swtestacademy.com › home › css selectors in selenium 17 tactics and examples
CSS Selectors in Selenium 17 Tactics and Examples
July 23, 2025 - (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.
🌐
Guru99
guru99.com › home › selenium › css selector in selenium
CSS Selector in Selenium
March 23, 2023 - 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.
🌐
Quora
quora.com › How-do-I-find-an-element-that-contains-specific-text-in-Selenium-Webdriver-Python
How to find an element that contains specific text in Selenium Webdriver (Python) - Quora
Answer (1 of 4): How about following approaches: With Exact word match: elementl = driver.find_element_by_xpath("//*[text()='Exact Match']") With Partial match: elementl = driver.find_element_by_xpath("//*[contains(text(), 'Partial Match')]") This stackflow answer should help you as well. Ha...
🌐
Medium
moniljoshi.medium.com › css-selectors-for-locating-elements-in-details-e6cbd62b99fc
Different CSS Selectors techniques for locating elements in Selenium Web Driver | by Monil Joshi | Medium
October 19, 2021 - We can write same element using ...endKeys("Mobile"); 3. Contains (*): It selects the element which matches with attribute having attribute value contains provided value followed by *= sign....
🌐
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
May 8, 2025 - Let’s execute the above CSS Selector in the ChroPath and observe that the p tag having the class attribute value ending with ‘in‘ got located as shown below: Now, let’s locate the above same p tag using the middle two letters of partial text in its class attribute value ‘main’. To achieve this, we need to use Contains (i.e.
🌐
Frugal Testing
frugaltesting.com › blog › selenium-tips-css-selector
Selenium Tips- CSS Selector
December 19, 2025 - Partial string matching is done using 3 three syntaxes:^=,$=,*=. Let’s discuss these three in detail with an example. ... e. Matching by inner text: one of the most useful pseudo classes :contains() matches elements with the desired text block