Recipes
One problem, one working solution, four languages. Each recipe explains the trade-offs and links to the lesson that covers the theory.
Elements & Locators
Retry on StaleElementReferenceException
Re-find an element and retry the action when the DOM re-renders between locating and using it.
Find Elements in Nested Shadow DOM
Walk through several shadow roots to reach an element inside deeply nested web components.
Check Whether an Element Exists Without an Exception
Test for presence, visibility or absence of an element cleanly, without try/catch and without waiting the implicit timeout.
Get the Text of a Hidden Element
Read text that getText() returns empty for: collapsed sections, off-screen items, and elements with display:none.
Interact With an Element Inside an iFrame and Return
Switch into a frame by element, act, and switch back safely, with a helper that guarantees the return even when an assertion fails.
Waits & Timing
Wait for a Loading Spinner to Disappear
Wait for an overlay or spinner to be gone before interacting, including the case where it never appeared.
Wait for Text to Change and Stabilise
Wait until an element's text differs from its previous value and stops changing, for counters, totals and live-updating fields.
Interactions
Click With a JavaScript Fallback
Try a real click first, then fall back to a JavaScript click only for the specific interception and visibility errors, with a log line so fallbacks are visible.
Hover a Menu and Click a Submenu Item
Open a hover-driven dropdown with the Actions API and click an item that only exists while the pointer is over the trigger.
Select a Dropdown Option by Visible Text
Choose options in native select elements with the Select helper, and handle custom (non-select) dropdowns built from divs.
Set a Date in a Date Picker
Type into the input when allowed, set the value directly when it is read-only, or drive the calendar widget when nothing else works.
Clear and Type Into a React or Angular Input Reliably
Replace the value of a framework-controlled input when clear() does not stick, using select-all plus type and the native setter fallback.
Handle an Unexpected Alert Without Failing
Configure the session to dismiss surprise alerts automatically, and accept or dismiss expected ones explicitly with a wait.
Browser & Session
Click a Link That Opens a New Tab and Switch to It
Detect the new window handle after a click, switch to it, do work, and return to the original tab without guessing handle order.
Highlight an Element for Debugging and Screenshots
Draw a temporary outline around the element a step is about to use so screenshots and videos show what the test targeted.
Set the Download Directory and Suppress Prompts
Configure Chrome, Firefox and Edge to save downloads silently into a directory the test controls, including PDFs that would otherwise open inline.
Dismiss a Cookie Consent Banner Once
Skip the consent banner in every test by pre-setting the cookie or storage key it checks, with a click fallback.
Files & Media
Wait for a File Download to Complete
Configure a download directory, trigger the download, and wait until the file exists and is no longer a partial file.
Upload a File Locally and Through a Grid
Send a file path to an input[type=file], make it work on a remote Grid or cloud with LocalFileDetector, and handle hidden file inputs behind styled buttons.
Screenshot a Single Element to a File
Capture just one component, named by test and timestamp, ready for a visual comparison tool or a bug report.
Verify the Contents of a Downloaded File
Assert on a downloaded CSV, PDF or Excel file: read it after download completes, check headers and rows, and clean up.
Network & Auth
Pass HTTP Basic Authentication
Get through a browser's basic auth prompt with BiDi's authentication handler, and the URL-embedded fallback for older setups.
Block Analytics and Third-Party Requests
Stop trackers, chat widgets and ad scripts from loading during tests to speed up pages and remove external flakiness.
Mock an API Response
Return a canned JSON payload for one endpoint so the UI shows empty, error or edge-case states without changing the backend.
Test Structure
Take a Screenshot on Test Failure Automatically
A framework hook for JUnit 5, pytest, Mocha and NUnit that saves a screenshot and page source only when a test fails.
Soft Assertions: Check Several Things, Report All Failures
Verify multiple fields on one page and report every mismatch at once instead of stopping at the first.
Pick the Browser, Headless Mode and Grid From Environment Variables
Run the same suite on Chrome, Firefox or Edge, locally or on a Grid, headed or headless, by changing environment variables instead of code.