Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 1 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


By posting your answer, you agree to the privacy policy and terms of service.

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