2

I'm writing some automated tests using Selenium in C# and I need to wait until a certain element is not in a Stale state. In java, I've once used something like ExpectedConditions.not(ExpectedConditions.stalenessOf(element), but I haven't yet found a way to do this in C#.

Is there a workaround for this problem or does Selenium in .NET not have the "Not" property at all?

1 Answers1

0

I was also looking for this not method and it seems there is no While or Until not construct available for use out of the box in C# using ExpectedConditions enumeration. This is a difference compared to Java or Python.

However according to this answer you can rewrite the problem using lambda:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until<IWebElement>((d) =>
{
    try {
      // Calling any method forces a staleness check
      element.isEnabled();
      return element;
    } catch (StaleElementReferenceException expected) {
      return null;
    }
});

Or you can use just another condition ExpectedConditions.ElementExists.

Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105