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('https://www.programsbuzz.com/search/node?keys=selenium');
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.