Element Lookup
Drama Finder provides static factory methods on element classes to locate Vaadin components using accessibility-first patterns. Instead of writing complex CSS selectors or XPath expressions, you can find elements by their accessible names, labels, and text content.Factory Method Pattern
Every element class provides static factory methods that combine tag names with ARIA role queries for robust, accessible element lookup.Basic Lookup by Label
Most input fields supportgetByLabel() which finds elements by their accessible label:
Factory methods use ARIA roles internally to ensure accurate matching. For example,
TextFieldElement.getByLabel() searches for elements with the TEXTBOX role.Lookup by Text Content
Buttons and other text-based elements supportgetByText() to find elements by their visible text:
ARIA Role-Based Lookup
Factory methods leverage Playwright’sgetByRole() with appropriate ARIA roles for each component type:
Scoped Lookups
All factory methods support both page-level and scoped lookups. Scoped lookups restrict the search to a specific container:Scoped Lookup Example
Lookup by ID or Custom Selector
Some elements like Grid provide additional lookup methods:Common ARIA Roles
Here’s a reference of ARIA roles used by common Vaadin components:Advanced Options
Factory methods that accept custom role options provide flexibility for complex scenarios:Best Practices
Prefer accessible names over CSS selectors
Prefer accessible names over CSS selectors
Always use factory methods that leverage accessible names (labels, text content) rather than CSS selectors or XPath. This makes tests more maintainable and accessible.
Use .first() for non-unique matches
Use .first() for non-unique matches
When your locator might match multiple elements, always use
.first() or scope your query:Scope lookups to reduce ambiguity
Scope lookups to reduce ambiguity
When multiple elements share the same label or text, use scoped lookups:
Related Concepts
- ARIA Roles - Deep dive into ARIA role mapping
- Locator Patterns - Advanced locator delegation patterns
- Assertions - Assert element state with auto-retry