4

enter image description hereenter image description here

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

1.

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

2.

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

3.

driver.findElement(By.xpath("html/body/div[1]/div/div/div")).getText();

  • can you share the HTML of the message, we can use better element locator. – Jeevan Bhushetty Oct 27 '16 at 17:13
  • we need your HTML – Yu Zhang Oct 27 '16 at 19:39
  • Added screen shot with attachment. – Imtiaz Ahmed Biplob Oct 28 '16 at 5:56
2

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!"); – Imtiaz Ahmed Biplob Oct 28 '16 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 '16 at 12:39
1

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.

0

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();
Assert.assertEquals(text,expectedText);

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.

0

You can verify your success message using assert.

Assert.assertEqual(Actual message, Expected Message);

OR

Assert.assertTrue(Expected Message.isDisplayed);
0
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");
}else{
    System.out.println("Please enter all details");
}
0

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"));
0

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

By.className(".pad.margin.no-print"))

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

$('pad.margin.no-print')

This will get you the element you need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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