我加了一些断点我的测试工作在调试模式。但是在删除断点之后,我得到了Timeout异常。我用了Thread.Sleep和它的工作是否有任何的替代品,而不是使用了Thread.Sleep硒的webdriver超时异常
[Test]
public void OpenStockControl()
{
driver.Navigate().GoToUrl("http://testdeneme.com");
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
IWebElement userName = driver.FindElement(By.Id("LoginNew1_tU"));
userName.SendKeys("TEST3");
IWebElement userPassword = driver.FindElement(By.Id("LoginNew1_tP"));
userPassword.SendKeys("A7535");
IWebElement buttonSubmit = driver.FindElement(By.Id("LoginNew1_bGo"));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
buttonSubmit.Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
SwitchWindow("ABC MA", driver);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("ext-gen54")));
element.Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
IWebElement element2 = wait.Until(ExpectedConditions.ElementExists(By.Id("ext-gen207")));
element2.Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
IWebElement element3 = wait.Until(ExpectedConditions.ElementExists(By.Id("ext-gen260")));
element3.Click();
}
我们需要看到一个例子。向我们展示一些失败的代码。如果您使用Sleeps并且它们工作正常,则意味着您有时间问题,应该正确等待页面上发生或发生的特定事件。 – Arran
谢谢,我添加了我的示例。这种方式不起作用... – bilgestackoverflow
它特别是一贯地失败了吗?此外,你应该知道,调用driver.Manage()。超时()。ImplicitlyWait()实际上并没有等待像Thread.sleep()方法做,它只是设置的驱动程序最长等待时间为隐等待。只需在代码开始时调用它(传入20秒参数)就足够了。阅读上ImplicitlyWait和WebDriverWait类 –