liveBook · Manning

Page Element Query Language

As explained in BDD in Action, Second Edition

The Page Element Query Language is Serenity/JS's portable query syntax for locating page elements and deriving information from them.

A registration form may have no test-friendly identifiers, leaving an acceptance test to find an input by the text of its label. A long selector tied to the form’s markup can be hard to reuse. Serenity/JS’s Page Element Query Language describes the desired element instead: find a form field with the right label, then find its input. section 15.2.6 section 15.3

Start with a PageElements collection located by a basic By selector. Filter it with where using an expectation, then select an element with first. PageElement describes a single element; of locates it within another element. Text.of supplies text for a query or assertion, and describedAs gives the result a readable name. section 15.2.6 section 15.2.2

Find the input labelled “Email”

Define fields as PageElements.located(By.css('mat-form-field')). Keep only fields where a mat-label is present and Text.of that label equals 'Email'; take the first match. Locate the input with PageElement.located(By.css('input')).of(matchingField), and describe it as the “Email” field. A task can then use Enter.theValue(emailAddress).into(Form.inputFor('Email')). The same approach can retrieve a field’s error text or select a button by its displayed text. section 15.2.6

Put these queries behind descriptive form or widget methods so tasks name the interaction rather than repeat locator details. The queries remain portable across supported web integration tools, including Selenium WebDriver, WebdriverIO, and Playwright. If adding test-friendly identifiers is practical, that remains an option; label-based queries help when it is not. section 15.2.6 section 15.3

How BDD in Action, Second Edition covers it

How deep it goes
Works through collection filtering, expectations, first-match selection, and nested element lookup; does not detail tool-specific selector translation.
Examples
Uses an Angular Material registration form to find an email input by label, retrieve field errors, and select buttons by text.
What it assumes
Assumes familiarity with web forms and selectors while defining the Serenity/JS element abstractions used to query them.
What you can do after
Apply it via Serenity/JS Web to write reusable element queries for acceptance-test interactions across supported web integration tools.
How it connects
Connects PageElements, PageElement, By selectors, assertions, Lean Page Objects, and Screenplay Pattern tasks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of BDD in Action, Second Edition. The section links point to the parts of the book it draws on.