ExpectedConditions.InvisibilityOfElementLocated 需要更多时间

Sud*_*thi 3 c# selenium wait selenium-webdriver

我遇到了一种情况,我需要等待一个元素消失(在 Firefox 中)。所以我尝试了不同的选项,但没有任何效果,所以尝试使用

new WebDriverWait(Drivers._driverInstance, new TimeSpan(0, 0, 2)).Until(ExpectedConditions.InvisibilityOfElementLocated(locator));
Run Code Online (Sandbox Code Playgroud)

这可行,但运行测试用例需要 26 秒。我评论这句话的时候花了一半的时间。为什么这种特殊方法需要更多时间。虽然我只提到了 2 秒,但实际上已经等待了近 10 秒。为什么会这样呢?有没有更快的方法来等待元素消失。

谢谢。

Gra*_*per 5

如果您的代码中在此显式等待之前有隐式等待。删除隐式等待并尝试。隐式和显式等待的混合可能会导致此行为。

检查一下并查看已接受的答案 - Clarification on the Cause of mix Implicit and Explicit waits of Selenium doc