Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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
add comment

2 Answers

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(By.id("AdminMainContent_AlertBoxMER1_lblMsg")));

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

//displaying the text in the alert box

share|improve this answer
add comment

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)
        {
            System.Threading.Thread.Sleep(200);
            count++;

        };

I would also suggest that you take a look at the following answer on SO http://stackoverflow.com/questions/5709204/random-element-is-no-longer-attached-to-the-dom-staleelementreferenceexception.

Note: the code above is in c#

share|improve this answer
add comment

Your Answer

 
discard

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.