Principle:Getgauge Taiko Element Assertion
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Testing |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Technique for verifying the presence, visibility, or state of page elements using smart selectors with automatic retry mechanisms.
Description
Element assertion is the process of checking whether specific elements exist on a page and are in expected states. In dynamic web applications, elements may not appear immediately after navigation or interaction -- they may load asynchronously via AJAX calls, lazy rendering, or client-side routing.
Robust assertions use an implicit wait mechanism that repeatedly checks for the element within a configurable timeout period, rather than checking once and failing immediately. This makes tests resilient to timing variations caused by network latency, server response times, and browser rendering performance.
Smart text-based selectors find elements by their visible text content rather than fragile CSS selectors or XPath expressions, making assertions more readable and maintainable. When a page redesign changes element IDs or class names, text-based selectors continue to work as long as the visible content remains the same. This approach aligns with testing best practices that advocate asserting on what the user sees.
Usage
Use after navigation or interaction to verify expected page state. For example, after form submission, assert that a success message appears. After navigation, assert that expected page content is visible. Combine with proximity selectors to assert elements near specific landmarks on the page, such as verifying a price appears near a product name.
Theoretical Basis
The assertion follows a polling pattern that bridges the gap between test execution speed and browser rendering time:
- Attempt to find element matching the given selector by searching the DOM for text content matches.
- If found, return true immediately, indicating the assertion passed.
- If not found, wait for the configured retryInterval (default 100ms) before trying again.
- Repeat the search-and-wait cycle until the retryTimeout (default 10000ms) is exceeded.
- If timeout exceeded, return false, indicating the element was not found within the allowed window.
Element search combines text matching (exact match attempted first, then contains match) with optional proximity filtering (near, above, below, toLeftOf, toRightOf). Proximity filtering calculates the spatial relationship between candidate elements and reference elements using their bounding rectangles, enabling assertions like "the text 'In Stock' appears near the product title."