我在这样的测试中有wait
:
WebDriverWait wait = new WebDriverWait(dr, TimeSpan.FromSeconds(30));
...
wait.Until((d) =>
{
if (d.FindElement(By.XPath("//*[@src='/loader.gif']")).Displayed)
{
System.Threading.Thread.Sleep(200);
return false;
}
else
{
return true;
}
});
我有时会得到 StaleElementReferenceException
。它在 95% 的时间内都有效,并且在测试中的不同地方都失败了。
错误:
Message: OpenQA.Selenium.StaleElementReferenceException : Element not found in the cache - perhaps the page has changed since it was looked up
最佳答案
我建议您尝试使用 ExpectedConditions,看看是否有帮助。
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
IWebElement loaderGif = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@src='/loader.gif']")));
关于c# - 等待时发生 StaleElementReferenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32845215/