Rayrun
โ† Back to Discord Forum

Very basic advice about getting an element by its text and then asserting by the same text..

fieldfare_24977posted in #help-playwright
Open in Discord
fieldfare_24977
fieldfare_24977

Is there a much nicer way to do this in PlayWright please? So far my two options appear to be:

await Expect(Page.Locator("li")).ToContainTextAsync("Invalid login attempt"); await Expect(Page.GetByText("Invalid login attempt")).ToContainTextAsync("Invalid login attempt");

Can we combine the GetByText somehow with the assertion? Thanks ๐Ÿ™‚

This thread is trying to answer question "Is there a more elegant way to get an element by its text and assert by the same text in Playwright?"

2 replies

Hi, instead of ToContainTextAsync, you could use ToBeVisibleAsync. Or you could use a locator which locates by something else than text.

fieldfare_24977
fieldfare_24977

The ToBeVisible thing works yeh ๐Ÿ™‚ thanks

Related Discord Threads

TwitterGitHubLinkedIn
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 [email protected].