2

This is my code:

foreach(IWebElement close in el.FindElements(By.ClassName("search-choice-close")))
{
    close.Click();
    TestHelper.WaitForAjaxCompletion(d);
}

The elements listed in FindElements are all list items in a "multiselect" (a select that's hidden behind a fancy ul/li javascript widget.

When the loop enters the second time, I get a StaleElementException, because clicking the first element updates the DOM.

What is a clean way to loop nicely over these elements that, I assume, must be 'found' after each DOM update?

1 Answer 1

1

I used a helper function to see if at least one element still exists. Because I'm finding a new element each loop, StaleElementException doesn't occur anymore.

while(isElementVisible(d, (By.ClassName("search-choice-close"))))
{
    d.FindElement(By.ClassName("search-choice-close")).Click();
    TestHelper.WaitForAjaxCompletion(d);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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