SeleniumBase for Rust supports three primary ways to express automation: direct API calls in Rust, CLI commands, and JSON-based scenarios. This page compares the formats and links to deeper guides.
What you will learn
- How the same action looks in each format.
- How selectors are represented across formats.
- When to choose one format over another.
The formats#
The most flexible format. Use it for production tests and complex logic.
The pure CDP engine has its own API, in which the
selector lives in a Locator instead of being passed to every call:
Useful for quick checks, CI one-liners, and ad-hoc debugging. Every sbrs
command starts its own browser and closes it when it finishes, so the one-liners
that make sense are the ones that take a URL:
For a flow with several steps, use a scenario or a Rust test.
Scenarios are portable and do not require recompiling a test binary. A scenario
is an object with a name and a list of steps; each step has an action and
the fields that action takes (url, css, text, contains, …):
Run the scenario:
The list of actions is in Recorder CLI.
sbrs record writes a different file, an array of recorded actions, which you
replay with sbrs replay.
Selector syntax#
SeleniumBase accepts multiple selector formats. See the Selectors Guide for details.
| Format | Example |
|---|---|
| CSS | #my-button |
| XPath | //button[@id='my-button'] |
| Link text | link=Sign in |
| Partial link text | partial_link=Privacy |
| Shadow DOM | my-app ::shadow button |
A selector beginning with /, ./ or ( (or an XPath axis such as parent::)
is XPath, the link=, link_text= and text= prefixes mean link text, and the
partial_link=, partial_link_text= and partial_text= prefixes mean partial
link text; anything else is CSS.
Choosing a format#
| Use case | Recommended format |
|---|---|
| Production regression tests | Direct API |
| CI smoke checks | CLI or JSON scenarios |
| Prototyping / demos | Recorder → Rust or JSON |
| Non-developer authors | JSON scenarios |