HTML code of the message Message display on site

I am unable to verify this sucess message. I am trying to use the following code:


String expectedText ="Dear admin, the Institution is deleted successfully!";
Assert.assertEquals("Dear admin, the Institution is deleted      successfully!",expectedText);


WebElement msg=driver.findElement(By.className("pad margin no-print"));
        String text=msg.getText();
String expectedText = "Dear admin, the Institution is deleted successfully!";



8 Answers 8


First two points: I cannot see any "Dear admin" in the message and instead of "assertEquals" try "assertTrue" and "contains". Then try:

String expectedMessage = "The Institution is deleted Successfully!";
String message = driver.findElement(By.xpath("//div[contains(@class,'callout callout-success')]")).getText();
Assert.assertTrue("Your error message", message.contains(expectedMessage));

I mentioned try message.contains because I think that the phrase "iMessage" will be also available in message! Check it.

  • I am trying to using following code but not working. Have any other solution to verify this success message. i am also adding iMessage with this but not working. /WebElement msg=driver.findElement(By.xpath("//div[contains(@class,'callout-success')]")); // String text=msg.getText(); //Assert.assertEquals(text,"Message:Dear admin, the Operator is added successfully!"); Oct 28, 2016 at 21:30
  • I wrote you already: try to check message.contains instead of equal. And only check for this expected result: "the Operator is added successfully". Have in mind that it is case sensitive and you should be careful of that.
    – Jose
    Oct 31, 2016 at 12:39

I look to use css first and for the elements and attributes I try to be as specific as needed without being overly specific and tying myself into page structure. In this case I would consider using:

success_message=driver.findElement(By.css(".content-wrapper .callout-success"))

along with

success_message.contains('the text')

This assumes that you don't have access to change the HTML source. If you do have that access I recommend you add semantic markup. Currently the page markup is mostly about the placement and appearance, e.g. content-wrapper and main-sidebar. These things will change over time (both in their usage and names) so I would look to add attributes about the mean of the content, e.g. a div#institutions tag and a div.feedback_message tag within it. Also tag the 'deleted' message itself so you aren't asserting the specific text which may change or be in another language.

Then you can do a find and assert that looks like:

Assert.assertTrue(driver.findElement(By.css(".institutions .feedback .deleted")

and you can see how readable that is - essentially " institutions feedback 'deleted' " exists, with no need for additional comments and robust against changes in both the future page layout and also the text used.


We should never use the compound class name while finding the element using the className method.

Use the below xpath

WebElement msg=driver.findElement(By.xpath("//div[contains(@class,'callout-success')]"));
String text=msg.getText();

NOTE: Please make sure that with above xpath giving how many elements.If it returning only one element then you can continue with that else you need to change according to that.


You can verify your success message using assert.

Assert.assertEqual(Actual message, Expected Message);


Assert.assertTrue(Expected Message.isDisplayed);
WebElement msg=driver.findElement(By.xpath(".//*[@id='message23']"));
String text=msg.getText();
if (msg.isEnabled() && text.contains("Registration completed successfully"))
    System.out.println("Successfully completed");
    System.out.println("Please enter all details");

This will return true if it find the success message

WebElement msg=driver.findElement(By.className("pad margin no-print"));
Assert.assertTrue(successMessage.contains("deleted successfully"));

When it comes to find element by class name where the element has multiple classes, separate the class names using .


If you wanna test your locator, just open the console tab from chrome or firefox browser and try this locator using this command:


This will get you the element you need


In IT industry various software testing techniques are used for different types of testing like web application testing, desktop application testing and medical device software testing where QA team verify the message validation after performing any scenario.

Below mentioned code can be used to verify success message using selenium:

WebElement msg = driver.findElement(By.xpath("//div[text()='The Institution is deleted Successfully!']")); Assert.assertTrue(msg.isDisplayed());

Not the answer you're looking for? Browse other questions tagged or ask your own question.