Giter VIP home page Giter VIP logo

Comments (4)

dtinth avatar dtinth commented on September 15, 2024 2

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
image image

Maybe the documentation can address getByText’s quirk (of also selecting visible elements) to nudge people into using getByRole more.

from playwright.

Skn0tt avatar Skn0tt commented on September 15, 2024 1

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.

qk5 avatar qk5 commented on September 15, 2024

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.

Skn0tt avatar Skn0tt commented on September 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.