Verify Text is not Present in Playwright

Profile picture for user arilio666

In playwright, we can verify a specific should not be present on a page using the built-in expect assertion of the playwright.

 test.only('two', async ({ page }) => { 
           await page.goto('');
            const wholePage = await page.locator('body')
            await expect(wholePage).not.toContainText('Spam Virus Alert')
  • Here we navigate to a search tab and consider this scenario where your page contains spam text.
  • We can take the body tag, and using a simple negative matcher from expect assertion, we can verify that the spam text is not present on the page.
  • This is how we can ensure a text is not present on a page using a playwright.