Skip to content

[Feature] Docs update for text= vs :has-text vs :text #5748

@thernstig

Description

@thernstig

I just read https://playwright.dev/docs/selectors/#text-selector

There are a few ways to look for text on a page, but I cannot from the docs deduct which one I should use. For example these three:

await page.click('#nav-bar >> text=Playwright');
await page.click('#nav-bar:has-text("Playwright")');
await page.click('#nav-bar :text("Playwright")');

To me, these seem functionally equivalent from the docs. Is that assumption incorrect?
Also, which one is the Best practice to use out of these? I've always used >> text before the other psuedo classes became available, but I am not sure that if I refactor my code which of these I should use. >> text has looks cleaner to me, easier to read, and is faster to type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions