Skip to main content

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 support getByLabel() 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 support getByText() to find elements by their visible text:

ARIA Role-Based Lookup

Factory methods leverage Playwright’s getByRole() with appropriate ARIA roles for each component type:
Using ARIA roles ensures your tests align with how assistive technologies and real users interact with your application.

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:
For elements without dedicated factory methods, construct them directly:

Common ARIA Roles

Using the wrong ARIA role will cause your lookups to fail. Always verify the role of the internal input element.
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

Always use factory methods that leverage accessible names (labels, text content) rather than CSS selectors or XPath. This makes tests more maintainable and accessible.
When your locator might match multiple elements, always use .first() or scope your query:
When multiple elements share the same label or text, use scoped lookups: