We can verify a text not present on a webpage in playwright java by using asserFalse assertion from either JUnit or TestNG.
page.navigate("http://www.programsbuzz.com");
Locator body = page.locator("body");
String bodyText = body.textContent();
Assert.assertFalse(bodyText.contains("Spam Message"), "Spam Text Not Found!!");
- Now consider this scenario where the page of your site is spammed with some texts.
- These unwanted texts are later cleaned and fixed, and as a tester, we need to verify the text is no longer present on that page.
- Using asserFalse and providing the unwanted text verifies and confirms that the texts are not there anymore.
- This is how we can verify text is not present in playwright java.