简体   繁体   English

C#-等同于Java的ExpectedConditions.not

[英]C# - Equivalent to java's ExpectedConditions.not

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. 我正在C#中使用Selenium编写一些自动化测试,我需要等到某个元素未处于过时状态。 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#. 在Java中,我曾经使用过ExpectedConditions.not(ExpectedConditions.stalenessOf(element) ,但是我还没有找到在C#中做到这一点的方法。

Is there a workaround for this problem or does Selenium in .NET not have the "Not" property at all? 是否有解决此问题的方法,或者.NET中的Selenium根本没有“ Not”属性?

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. 我也一直在寻找这not方法,似乎没有while或者until不使用构造可使用现成的C# ExpectedConditions枚举。 This is a difference compared to Java or Python. 与Java或Python相比,这是有区别的。

However according to this answer you can rewrite the problem using lambda: 但是,根据此答案,您可以使用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 . 或者,您可以只使用另一个条件ExpectedConditions.ElementExists

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM