Skip to content

[Feature]: Add a locator builder method withTextEquals() #4099

@mirao

Description

@mirao

What are you trying to achieve?

In DOM sometimes we have multiple elements ".item" with a text containing "Add", e.g. "Add", "Add problem" or just a text "Addison Ryan" (a user full name).

When a test clicks on a link (".item") with the text "Add", it can't use locate(".item").withText("Add") because all "Add*" elements match (and thus any of them can be "randomly" selected).

It would be handy to have a method withTextEquals() (an analogy to the Playwright helper's method seeTextEquals()) that selects a locator which's text equals to passed argument.

XPath allows .= and text()=, see https://stackoverflow.com/a/34595441/10172701
IMHO .= is better for our case as it computes string as a concatenation of all strings inside element, so it behaves similar as contains(., ${text}) (used by withText())

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