Home > Back-end >  How can I check to see if specific text is on a page using Playwright test automation
How can I check to see if specific text is on a page using Playwright test automation

Time:12-15

I am working on my first test automation project using Playwright for .NET. For one of the tests I need to check for a specific bit of text on a page. I have been able to do a number of other tests but I can't seem to figure this one out. The JavaScript implementation includes "has-text" but I don't see that for .NET.

I used page.Locator("my text") but I don't know how to check if "my text" in fact exists on the page.

CodePudding user response:

You could do something like this:

var myTextLocator = await Page.GetByText("my text");
await Expect(myTextLocator).ToHaveCountAsync(1);

CodePudding user response:

This works:

var foo = await page.Locator("my text").TextContentAsync();

  • Related