Closed rob4629 closed 5 months ago
TestCafe has an option to filter elements by their visibility, either using .filterVisible or using with (their version of filter) visibilityCheck.
with
filter
It would be great to have something similar with Playwright, to help keep tests stable
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:
visible: false
const myHiddenButton = page.getByRole('button', { name: 'My Button' }).filter({ visible: false }); await expect(myHiddenButton).toBeHidden();
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
submit
.nth(x)
x
@rob4629 Take a look at this documentation page.
Closing as per above.
🚀 Feature Request
TestCafe has an option to filter elements by their visibility, either using .filterVisible or using
with
(their version offilter
) visibilityCheck.It would be great to have something similar with Playwright, to help keep tests stable
Example
Can be used to target hidden elements too, by specifying
visible: false
for the filter method: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, andx
could change depending on the variation