HasData
Back to Q&A

Is there a CSS selector that matches an element by the text it contains?

No. Standard CSS has no selector for matching elements by their text content. A :contains() pseudo-class was proposed for CSS Selectors Level 3 but was dropped from the spec, and no browser supports it natively. To select by visible text you have to leave CSS. The common routes are tagging the relevant elements with a data-* attribute and matching the attribute instead, querying textContent in JavaScript and applying a class at runtime, or using XPath (//div[contains(text(),'Target')]) inside a scraping or automation tool like Selenium or Playwright. The :contains() syntax you may have seen in jQuery, Cypress, or uBlock Origin is a tool-specific extension and does not work in browser CSS. :has() is broadly supported now but matches by descendant structure, not text, so it does not solve this problem.

Write selectors against pages that actually loaded

HasData fetches blocked or rendered targets, so your selectors have something to query.