gpt4 book ai didi

c# - .NET Selenium NoSuchElementException; WebDriverWait.Until() 不起作用

转载 作者:行者123 更新时间:2023-11-30 12:44:19 26 4
gpt4 key购买 nike

我们有一个 .NET 4.5、MVC、C# 项目。我们正在使用 Selenium 进行 UI 测试,并且测试在我们拥有 wait.Until() 的行上不断失败。一个这样的例子是:

NoSuchElementException was unhandled by user code
An exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll but was not handled in user code
Additional information: Unable to locate element: {"method":"css selector","selector":"#assessment-472 .status-PushedToSEAS"}

它被扔在这里:

Thread.Sleep(600);
wait.Until(drv => drv.FindElement(By.CssSelector("#" + assessmentQueueId + " .status-PushedToSEAS")));

我可以看到浏览器打开,我看到它到达那个点,我可以检查元素以查看该元素是否存在。它的 id 完全正确。

我们有这个问题很多,到目前为止,解决方案是在它前面抛出 Thread.Sleep(600)(或某个类似的时间)。 wait.Until() 的全部意义在于不必这样做,这使我们的测试套件变得很长。此外,正如您在上面的示例中看到的,有时即使在它前面放置了一个 Thread.Sleep() 之后我们也会遇到问题,我们必须延长时间。

为什么 .NET Selenium 的 WebDriver.Until() 不工作,有没有不同的方法来做同样的事情而不只是等待一段设定的时间?同样,问题是间歇性的,这意味着它只是有时发生,并且它可能发生在任意数量的 wait.Until() 语句中,而不仅仅是显示的那个!

编辑:

这是一个类变量。private WebDriverWait 等待;

它是这样实例化的:

this.wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

最佳答案

我决定不使用 WebDriverWait.Until(),而是在主驱动程序上使用隐式等待:

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

我完全相信 this answer关于给我这个想法的另一个问题。

关于c# - .NET Selenium NoSuchElementException; WebDriverWait.Until() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28864493/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com