Comments (4)
I want to chime in that a workaround for this is to use getByRole
instead of getByText
, as we can exploit the fact that invisible elements do not have a role:
when visible | when hidden |
---|---|
Maybe the documentation can address getByText
’s quirk (of also selecting visible elements) to nudge people into using getByRole
more.
from playwright.
Also, an interesting observation in API design: in getByText("...", { visible: true })
, the visible
option is trimodal! With the defaults we have, { visible: false }
clearly means "only select invisible", { visible: true }
means "only select visible", and { visible: undefined }
means "do the default", which is selecting both visible and invisible elements.
from playwright.
Update: Upon reading more on the playwright documentation, I found out the following also works:
page.getByText('Waiting for response...', { exact: true }).locator('visible=true');
But I still think if we can expose visible as an option, it will look cleaner. Please feel free to correct me if I am wrong.
Thank you.
from playwright.
Hey @qk5! We've discussed this in our team sync yesterday. The fact that by default, getByText
selects not just visible elements but also invisible ones is a design regret of ours. All the RTL-Style selectors (think getByText
, getByAltText
, getByRole
) are modeled after human perception, and that means that it's surprising for it to include hidden elements. So if we could go back in time, we would change the defaults so that getByText
only selects visible elements.
We can't though, and we'd prefer not to introduce breaking changes in such a fundamental part of our API. Even if we made this behaviour a config toggle, we'd be forking our userbase into two fundamentally different behaviours, which would lead to even more confusion. Really bad, especially when you consider that libraries have no way of detecting it.
Now, the visible
option you propose is an interesting way out of this! Before we think about implementing it though, we'd like to understand how big this problem really is. I'll label it "P3: Collecting Feedback" and then we can collect some upvotes on the issue. Hopefully that gives us some perspective on the gravitas of this, and sleep a couple of nights about other solutions to the problem.
from playwright.
Related Issues (20)
- [Bug]: Action pointer rendered for each iframe in trace viewer snapshot HOT 1
- [Bug]: viewport from playwright.config.js is not honored. HOT 1
- [Bug]: Memory Consumption Issue with Playwright 1.44.1- Assistance Required HOT 1
- [Feature]: Unable to Disable Screenshot took and Attachment for Certain Tests HOT 4
- Error: duplicate test title HOT 1
- [Bug]: VSCode extension Watch mode not working (MacOS) HOT 3
- [Feature]: I pass the json and it automatically generates request & response HOT 4
- [Regression]: `tsconfig.json`'s `compilerOptions.paths` no longer working in 1.47 HOT 4
- [Bug]: React select input click step fails on safari, but passes on chrome HOT 2
- [Bug]: 'latest' tag is pointing to "v1.46.1-jammy" docker image HOT 10
- [Bug]: @playwright/test 1.47.0 broken for tsconfig alias imports HOT 3
- [Feature]: clock feature inside tests HOT 1
- [Bug]: logPolitely logs on stdout HOT 6
- [internal]: Screenshots instead of Snapshots improvements
- [Feature]: Passing variables from playwright.config to test.spec HOT 4
- [Bug]: Trace report doesn't show up on report - Inconsistent behaviour. HOT 1
- [Bug]: VSCode Playwright extension "Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker" HOT 1
- [Bug]: Default GitHub Action says ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL Command "playwright" not found HOT 2
- [Docs]: NOTE in the Introduction / Clock page
- [Bug]: Recorder doesn't work when `Array.prototype.toJSON` is declared HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright.