Use WebdriverIO’s $ command to locate one element and $$ to locate multiple elements. CSS is the default selector strategy, but you can also target links by text, use XPath or accessible names, and register custom strategies. Prefer a locator that identifies the intended control without depending on incidental styling; use a test ID or a well-chosen accessible name when appropriate.
Choose a selector that identifies the right element
WebdriverIO’s $ and $$ are element-query commands, not jQuery or Sizzle. The WebDriver Protocol provides several selector strategies to query an element. In WebdriverIO, CSS is the default, with additional selector forms for text, XPath, accessibility-oriented lookup, and custom application-specific rules.
| Strategy | Example | When it can fit | Trade-off to consider |
|---|---|---|---|
| CSS | $('[data-testid="submit"]') |
A unique test ID or stable application attribute identifies the target. | Generic tags and classes tied to styling may match the wrong element or change as the design changes. |
| Text | $('=WebdriverIO') |
Locate a link by exact text, or use *= for partial text. |
Visible text can change with localization or copy edits; use it when the wording itself is a meaningful target. |
| Accessible name | $('aria/Submit') |
The control has a meaningful accessible name that describes it to users of assistive technology. | Behavior depends on the session: BiDi-capable browsers use accessibility-tree lookup first, while Classic sessions use an XPath approximation. |
| XPath | $('//ul/li[2]') |
The target is best expressed through its relationship to other nodes in the document tree. | Structural expressions can be sensitive to markup changes; Classic-session accessible-name approximations may also be slower on large pages. |
| Custom strategy | browser.custom$('strategyName', args) |
The application has a lookup rule that ordinary selectors do not express clearly. | Requires registering the strategy and a web environment where execute can run. |
There is no universal speed ranking for all selector forms. In the documented accessibility case, BiDi accessibility-tree lookup is typically faster than the Classic XPath approximation; actual test behavior depends on the page and environment.
Write and scope element queries
Locate one element with $
Use $ when the test expects one target. For a page with a dedicated submit test ID, for example:
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
const submit = await $('[data-testid="submit"]')
The command returns an element handle that you can use in the rest of the test. Choose a selector that is specific enough to identify the intended element rather than relying on a broad query such as $('button').
Locate multiple elements with $$
Use $$ when you intend to work with a collection of matching elements:
const rows = await $$('.results-list li')
Make sure the selector describes the collection you need. A broad selector can include unrelated elements, so scope it to a distinctive container when necessary.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Use WebdriverIO’s text selector forms
For a link whose exact label is WebdriverIO, use =; for partial link text, use *=:
const docsLink = await $('=WebdriverIO')
const partialLink = await $('*=driver')
These are WebdriverIO selector forms, not CSS syntax. Text is often useful for a user-facing target, but consider whether localization, copy changes, or duplicate labels could make it unstable.
Choose accessible names for meaningful controls
An accessible-name selector can express the control by the name users and assistive technology perceive:
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
const submitByName = await $('aria/Submit')
Use a name that is meaningful and unique in the relevant scope. The selector guide describes an example where button=Submit is its strongest recommendation for a user-facing target, while aria/Submit and a dedicated test ID are good choices. These are contextual recommendations, not a rule that visible text is always the most stable locator.
Use XPath when relationships matter
XPath can describe a target in relation to its ancestors, descendants, or position:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →const item = await $('//ul/li[2]')
Use it when that relationship is the useful part of the locator. If a stable test ID or user-facing name identifies the target more directly, prefer that simpler expression.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Scope queries without unnecessary lookups
Every $ or $$ query attempts to locate elements. A single combined selector can be clearer and require fewer lookups than repeatedly chaining queries. Chain when it narrows the search to a component or deliberately changes selector strategy from parent to child.
const select = await $('custom-datepicker').$('#calendar').$('aria/Select')
This scopes the search to a date-picker component, then to its calendar, and finally locates the control by accessible name. WebdriverIO does not let you mix multiple selector strategies in one selector string; use chained queries to move from a scoped parent to a child with another strategy.
Register a custom locator strategy when needed
For an application-specific lookup rule, register a strategy with browser.addLocatorStrategy, then call browser.custom$ for one match or custom$$ for multiple matches. The documented example strategy returns the result of document.querySelectorAll(selector):
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
browser.addLocatorStrategy('myStrategy', (selector) => {
return document.querySelectorAll(selector)
})
const oneMatch = await browser.custom$('myStrategy', 'button.submit')
const allMatches = await browser.custom$$('myStrategy', 'button.submit')
Define a custom strategy only when it captures a reusable application rule that ordinary selectors do not express well. Custom strategies need a web context where execute can run.
Account for WebdriverIO version and session type
WebdriverIO v9 and Shadow DOM
WebdriverIO v9 automatically pierces Shadow DOM. The selectors guide says the special >>> deep selector is no longer required; remove that prefix when migrating older selectors.
aria/ behavior in BiDi and Classic sessions
For BiDi-capable browsers, WebdriverIO first tries browsingContext.locateNodes with an accessibility locator against the browser’s accessibility tree. If no match is found, it falls back to a Classic XPath heuristic so existing queries can still match. Classic sessions use the XPath approximation directly, which the guide warns can be slower on large pages. Do not assume the two session types use identical lookup behavior.
Common selector problems and fixes
| Symptom | Likely cause | Practical fix |
|---|---|---|
| The query matches the wrong control or more than one target. | The selector is too generic, such as a bare tag or a repeated styling class. | Narrow it with a stable test ID, meaningful accessible name, distinctive text, or a scoped parent query. |
| A text selector stops matching after a language or copy change. | The locator depends on visible wording that changed. | Use a stable test ID or accessible name where suitable, or update the expected text for the locale under test. |
An aria/ query behaves differently across browser sessions. |
BiDi-capable sessions try accessibility-tree lookup first; Classic sessions use an XPath approximation. | Confirm the session type and browser support, and account for the documented Classic-session behavior when diagnosing the locator. |
An old Shadow DOM selector includes >>>. |
The selector may predate WebdriverIO v9’s automatic Shadow DOM piercing. | For v9, remove the special prefix and use the regular selector. |
| A custom strategy cannot evaluate its lookup. | The query is not running in a web environment where execute is available. |
Run it in a supported web context or use a standard selector strategy that fits the target. |
Or skip the browser setup
If your goal is to save a page screenshot rather than test an element locator, ScreenshotNeo is a website screenshot API and MCP server: one GET request can return a PNG, JPEG, WebP, or PDF. Cookie banners, newsletter popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. AI agents can take screenshots through its MCP server. The free plan includes 1,000 screenshots per month with no card, and paid plans start at $5 for 3,000.
Recommended Free Tools
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for the request options. Sign up for 1,000 free screenshots a month with no card.
Quick Recap
Sources
- WebdriverIO Selectors
- WebdriverIO Best Practices
- WebdriverIO
custom$API - WebdriverIO Browser Object API
- WebdriverIO element
$API
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

