← Back to Discord Forum

Why is playwright not detecting elements?

Is there a reason why the first line of code works and the second one doesn't? I have also attached what the webpage looks like.


self.page.locator("[data-test="BundleGroup"]").get_by_role("checkbox").filter(has_text='Estoppel Certificate').first.check()


This thread is trying to answer question "Why is playwright not detecting elements?"

5 replies

Locators are strict by default and will return nothing if several elements match



with 1.34, you may use "and" condition, see https://playwright.dev/python/docs/release-notes#version-134

Example New locator.and_() to create a locator that matches both locators.

button = page.get_by_role("button").and_(page.get_by_title("Subscribe"))

The second one filters by text, I’m not sure why it does not work. And they both have the .first attribute.

@p01___ it does not throw an error. It just does not detect the element at all (talking about the one that filters with has_text)

Could you share the html of the page? you can check with codegen about the locator generated.

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.