Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Add option to filter Locators by visibility #30615

Closed
rob4629 opened this issue Apr 30, 2024 · 2 comments
Closed

[Feature]: Add option to filter Locators by visibility #30615

rob4629 opened this issue Apr 30, 2024 · 2 comments

Comments

@rob4629
Copy link

rob4629 commented Apr 30, 2024

馃殌 Feature Request

TestCafe has an option to filter elements by their visibility, either using .filterVisible or using with (their version of filter) visibilityCheck.

It would be great to have something similar with Playwright, to help keep tests stable

Example

const myVisibleButton = page.getByRole('button', { name: 'My Button' }).filterVisible();

Can be used to target hidden elements too, by specifying visible: false for the filter method:

const myHiddenButton = page.getByRole('button', { name: 'My Button' }).filter({ visible: false });
await expect(myHiddenButton).toBeHidden();

Motivation

We have some elements which are named the same (e.g. submit button), and it will make the tests more readable than using .nth(x)... especially since we have a lot of variations of the same page, and x could change depending on the variation

@dgozman
Copy link
Contributor

dgozman commented Apr 30, 2024

@rob4629 Take a look at this documentation page.

@mxschmitt
Copy link
Member

Closing as per above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants