Skip to main content
Bromate provides a powerful selector engine based on CSS selectors with additional capabilities. This page demonstrates common selector patterns with examples to help you effectively extract data from web pages.

Text Matching

Basic Text Matching

article:has-text("Bromate") Matches any <article> tag that contains the text “Bromate”, even nested inside child elements.

Exact Text Matching

button:text-is("Log") Matches elements with exact text content. Case-sensitive and trims whitespace.

Text Pattern Matching

button:text-matches("Log\\s*in", "i") Matches text using regex patterns. The example matches “Login”, “Log in”, “log IN”, etc.

Layout-Based Selectors

Position-Based

input:right-of(:text("Username")) Matches input fields that are to the right of text “Username”
button:near(.promo-card) Matches buttons within 50 pixels of elements with class “promo-card”

Distance Specification

button:near(:text("Username"), 120) Matches buttons within 120 pixels of text “Username”

Element State and Visibility

button:visible Matches only visible button elements

Nested Elements

Has-Text with Specific Elements

article:has-text("Bromate") Matches article elements containing “Bromate” text anywhere inside

Parent-Child Relationships

#nav-bar :text("Home") Matches elements with text “Home” inside #nav-bar element

Multiple Conditions

button:has-text("Log in"), button:has-text("Sign in") Matches buttons containing either “Log in” or “Sign in” text

XPath Selectors

xpath=//button Matches any button element anywhere in the document
xpath=//div[@id='main']//button Matches button elements inside div with id=“main”

Label and Form Controls

label:has-text("Password") Matches label element containing “Password” text and can be used to target its associated input

Framework-Specific Selectors

React Components

_react=BookItem Matches React components named BookItem
_react=BookItem[author = "Steven King"] Matches BookItem components with specific author prop

Vue Components

_vue=book-item Matches Vue components named book-item
_vue=book-item[author = "Steven King"] Matches book-item components with specific author prop

Testing-Specific Attributes

data-testid=submit Matches elements with data-testid=“submit”
id=login-form Matches elements with id=“login-form”

CSS Selectors

Basic CSS

css=button Matches any button element using standard CSS selector

CSS with Text Matching

css=#nav-bar :text("Home") Matches smallest element containing “Home” text inside #nav-bar

CSS with Has Selector

article:has(div.promo) Matches article elements that contain div with class “promo”

Nth Match Selectors

:nth-match(:text("Buy"), 3) Matches the third element containing text “Buy”

Chaining Selectors

Basic Chaining

article >> .bar > .baz >> span[attr=value] Chains multiple selectors, each queried relative to the previous match

Intermediate Matches

*css=article >> text=Hello The * prefix captures the article element instead of the text element

Layout Combinations

[type=radio]:left-of(:text("Label 3")):near(.form-group) Complex selector combining position and proximity

Role-Based Selectors

[role="button"][aria-label="Submit"] Matches elements with specific ARIA roles and labels

Union Selectors

xpath=//span[contains(@class, 'spinner__loading')]|//div[@id='confirmation'] Matches elements that satisfy either condition

CSS Pseudo-Classes

Visibility Matching

button:visible Only matches visible buttons, useful to distinguish between similar elements

Text Content Matching

article:has-text("Bromate") Matches elements containing specified text somewhere inside

Multiple Text Conditions

button:has-text("Log in"), button:has-text("Sign in") Matches elements that satisfy any of the text conditions

Element Containment

article:has(div.promo) Returns elements that have matching children

Nth Element Selection

:nth-match(:text("Buy"), 3) Matches the nth occurrence of an element (1-based index)

Advanced Layout Selectors

Above/Below

button:above(.footer) Matches buttons that are above the footer element
input:below(.header) Matches inputs that are below the header element

Left/Right Positioning

button:right-of(.sidebar) Matches buttons positioned to the right of the sidebar

Near Elements

button:near(.card, 100) Matches buttons within 100 pixels of a card element

React Component Properties

Multiple Property Matching

_react=BookItem[author *= "king" i][year = 1990] Matches React components with multiple property conditions

Nested Property Values

_react=[some.nested.value = 12] Matches components with specific nested property values

Property Pattern Matching

_react=BookItem[author = /Steven(\\s+King)?/i] Matches components where properties match a regex pattern