Search code examples
playwrightplaywright-typescript

Playwright: Selector for an element inside a specific div


let's assume I have multiple p-elements with the same text on my page and I want to check the visibility of a specific one that has to be inside a section-element.

<section class="contact__block">
    <p>...</p>
    <p>This is the one I'm looking for!</p>
    <p>...</p>
</section>

In addition: none of the p-elements inside the section is named or has an id. Is this possible and how does the selector look like?

Thanks and have a great day!


Solution

  • A more Playwright-esque approach would be:

    page.locator("section").getByText("This is the one I'm looking for!")