![](/img/trans.png)
[英]Selenium Webdriver “Expectedconditions.not” is not working as expected
[英]C# - Equivalent to java's ExpectedConditions.not
我正在C#中使用Selenium編寫一些自動化測試,我需要等到某個元素未處於過時狀態。 在Java中,我曾經使用過ExpectedConditions.not(ExpectedConditions.stalenessOf(element)
,但是我還沒有找到在C#中做到這一點的方法。
是否有解決此問題的方法,或者.NET中的Selenium根本沒有“ Not”屬性?
我也一直在尋找這not
方法,似乎沒有while或者until不使用構造可使用現成的C# ExpectedConditions
枚舉。 與Java或Python相比,這是有區別的。
但是,根據此答案,您可以使用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;
}
});
或者,您可以只使用另一個條件ExpectedConditions.ElementExists
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.