PageElements represents a collection of web elements and provides queries for selecting members of that collection. It complements PageElement, which models one element, and works with Serenity/JS web APIs. section 15.2.2
Use PageElements to:
- Locate groups of elements with By.css, By.xpath, By.id, or related selectors. section 15.2.2
- Filter the collection with Page Element Query Language expectations such as presence and matching text. section 15.2.6
- Select an individual match with operations such as first(), then scope related PageElements with .of(). section 15.2.2 section 15.2.6
Finding a labelled form field
Define form fields as PageElements.located(By.css('mat-form-field')). Filter them by the presence of a label and matching label text, select the first match, and scope the input to that field: Form.input().of(Form.fieldCalled(name)). section 15.2.6
import { PageElements, By } from '@serenity-js/web'
class Form {
public static fields = () =>
PageElements.located(By.css('mat-form-field'))
.describedAs('form fields')
// ...
}
The listing shows the basic PageElements declaration for a reusable collection of form fields. section 15.2.6
