Sign up ×

I need to verfiy the dialog box displayed on clicking a 'Save' button for below conditions.

  1. Whether the dialog box is displayed?
  2. Text present in the dialog box?

I have tried using all locators and finally using css selector as below.

driver.findElement(By.cssSelector("#AdminMainContent_AlertBoxMER1_lbtnOK > span")).isDisplayed()

//to verfiy whether dilaog box is displayed

and i got exception as below

org.openqa.selenium.StaleElementReferenceException: Element is no longer valid (WARNING: The server did not provide any stacktrace information)

share|improve this question

2 Answers 2

It sound like you need to do an explicit check on the DOM because the page state is changing after you it the save button. You will need to recheck the DOM for the element post save. You could try something like this:

            int count = 0;
        while (!driver.FindElement(By.CssSelector("#AdminMainContent_AlertBoxMER1_lbtnOK > span")).Displayed || count < 50)


I would also suggest that you take a look at the following answer on SO

Note: the code above is in c#

share|improve this answer
up vote 0 down vote accepted

Hi guys i got it working when i changed the code as below

new WebDriverWait(driver, 100).until(ExpectedConditions.presenceOfAllElementsLocatedBy("AdminMainContent_AlertBoxMER1_lblMsg")));

//waiting for the alert box to get displayed System.out.println(driver.findElement("AdminMainContent_AlertBoxMER1_lblMsg")).getText());

//displaying the text in the alert box

share|improve this answer

Your Answer


