Skip to content

[Feature]: locator.waitFor({ attribute }) #41317

Description

@MaruschkaScheepersW

🚀 Feature Request

Title: Add locator.waitFor({ attribute }) for waiting on attribute presence/value

Summary:
Currently the only way to wait for a locator's attribute to appear or change is via expect(locator).toHaveAttribute(...) or page.waitForFunction(...). Both work, but neither fits flows where you just want to wait (not assert) for an attribute before continuing, similar to locator.waitFor({ state: 'visible' }).

Proposal:
Extend locator.waitFor() to accept an attribute condition:

Example

await toggle.waitFor({ attribute: { name: 'aria-expanded' } });

Motivation

Clearer intent than expect(...).toHaveAttribute(...) when the goal is synchronisation, not assertion (e.g. inside a Page Object action method, where assertions don't belong).

I would not expect to write a ui test simply checking if the the sidenav is expanded. But I would have some method on my page object interacting with the side nav and I would like it to fail if the side nav is not expanded

async function expandSubMenu(){

await openSideMNavigation();
await menuItemToggle.click();
await menuItemToggle.waitFor({ attribute: { name: 'aria-expanded' } });

}

This way if something strange happens taht causes the item to close ( I have had this due to a scroll event) , the waitForr can fail.

We prefer not asserting on page objects.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions