Imagine a scenario where you fill out all the necessary information on a form, click Save, and then receive a message confirming that the form was saved successfully. The message pops up for about 6-7 seconds before fading away. Here is the HTML code for the message:
<div data-notify="container" class="alert-success animated" role="alert" data-notify-position="top-right">
<span data-notify="title">
<span class="glyphicon glyphicon-ok">::before</span>
<span>Saving</span>
<span data-modify="message">Successfully saved</span>
</span>
</div>
You try to verify the text "Successfully saved" with the following code:
String message = driver.findElement(By.cssSelector("span.glyphicon glyphicon-ok")).getText();
assertTrue(message.contains("Successfully saved"));
However, this assertion fails because the element cannot be located.
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"span.glyphicon glyphicon-ok"}
You are unsure whether your code is incorrect or if the message fades away too quickly for the driver to find the element.
Any assistance or suggestions for correction would be greatly appreciated.
Thank you, Danny