We can verify a text not present on a webpage in selenium by using asserFalse assertion from either JUnit or TestNG.
WebDriverManager.chromedriver().setup(); ChromeDriver driver = new ChromeDriver(); driver.get("https://www.programsbuzz.com/search/node?keys=selenium"); driver.manage().window().maximize(); WebElement bodyFull = driver.findElement(By.tagName("body")); String bodyText = bodyFull.getText(); Assert.assertFalse(bodyText.contains("Spam Virus"), "Spam Message Text Is Not Present"); driver.close();
- 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 selenium java.
Thu, 03/16/2023 - 12:32