This thread is trying to answer question "Is the use of `to_be_visible()` in the shared Python code snippet correct, and can it be improved?"
Yeah, that should work fine. The only thing I'd recommend is using a better locator if possible; the Playwright Locators guide (https://playwright.dev/python/docs/locators) is fantastic. div.benefits-container ul li
seems like it could be brittle, and it's best to avoid nth()
methods. Without seeing your app, I can't recommend a better locator, but to avoid the nth(0)
you could probably do expect(locator.get_by_text("No Cost Transition")).to_be_visible()
in place of your last 2 lines.
disclaimer: I use typescript instead of python for Playwright, so my suggestion code is untested and might be bad syntax
you're welcome!
I avoid using only text as a locator and tend to use chaining/filtering with text to narrow things down.
So in your case, I'd find a different locator for the benefits container, either a data-testid
or a role, and then chain like locator.get_by_text()
. Not sure what the filtering syntax is for python, but it's very handy so definitely read up on that ๐
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].