How to assert elements contains text in Selenium using JUnit
Use:
String actualString = driver.findElement(By.xpath("xpath")).getText();assertTrue(actualString.contains("specific text"));
You can also use the following approach, using assertEquals
:
String s = "PREFIXspecific text";assertEquals("specific text", s.substring(s.length()-"specific text".length()));
to ignore the unwanted prefix from the string.