new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · API reference · all subjects

selectors

12 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Selectors.register async method signature

Selectors.register is an async method that takes a name parameter (string) and a script parameter. The method registers a custom selector engine before page creation.

Selectors.register name parameter constraints

The name parameter for Selectors.register specifies the prefix used in selectors (e.g., {name: 'foo'} enables foo=myselectorbody selectors). The name may only contain characters [a-zA-Z0-9_].

Selectors.register script parameter JavaScript

For JavaScript, the script parameter accepts a function, string, or object. If an object, it has two optional properties: path (a path to a JavaScript file, resolved relative to current working directory if relative) and content (raw script content). The script evaluates to a selector engine instance and is evaluated in the page context.

Selectors.register script parameter Java

For Java, the script parameter accepts a string or path. The script evaluates to a selector engine instance and is evaluated in the page context.

Selectors.register script parameter Python

For Python, the script parameter is optional and accepts raw script content as a string. There is also a path parameter (required) that specifies a path to a JavaScript file, resolved relative to current working directory if relative.

Selectors.register script parameter C#

For C#, the script parameter is a string that evaluates to a selector engine instance and is evaluated in the page context. There is also a path parameter that specifies a path to a JavaScript file.

Selectors.register contentScript option

The contentScript parameter is an optional boolean that determines whether to run the selector engine in an isolated JavaScript environment. This environment has access to the same DOM but not JavaScript objects from the frame's scripts. It defaults to false. Note that running as a content script is not guaranteed when this engine is used together with other registered engines.

Selectors.setTestIdAttribute method signature

Selectors.setTestIdAttribute is a synchronous method that takes an attributeName parameter (string). It defines a custom attribute name to be used in Page.getByTestId. The default test id attribute is 'data-testid'.

Selectors.setTestIdAttribute attributeName parameter

The attributeName parameter for Selectors.setTestIdAttribute accepts a string. To match elements with any of several attributes, pass them as a comma-separated list, e.g. 'data-pw,data-ti'.

Custom selector engine structure

A custom selector engine instance must have two methods: query(root, selector) which returns the first element matching the given selector in the root's subtree, and queryAll(root, selector) which returns all elements matching the given selector in the root's subtree.

Selectors.register prerequisite

Selectors must be registered before creating the page.

Custom selector usage example

An example of registering a tag name selector engine: const createTagNameEngine = () => ({ query(root, selector) { return root.querySelector(selector); }, queryAll(root, selector) { return Array.from(root.querySelectorAll(selector)); } }); await selectors.register('tag', createTagNameEngine); Then use it with page.locator('tag=button') and combine with built-in locators like page.locator('tag=div').getByText('Click me').click().

Give your agent this brain