gpt4 book ai didi

c# - Selenium WebDriver 超时异常

转载 作者:太空宇宙 更新时间:2023-11-03 13:24:12 25 4
gpt4 key购买 nike

我添加了一些断点我的测试在 Debug模式下工作。但是删除断点后我得到超时异常。我使用了 Thread.Sleep 并且它可以工作是否有任何替代方法而不是使用 thread.sleep

        [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();
}

最佳答案

您的等待时间 (WebDriverWait) 正在等待 10 秒让元素出现。不满足 ExpectedCondition,因此抛出 Exception。您可以增加调用 WebDriverWait 构造函数的时间量。

关于c# - Selenium WebDriver 超时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23007614/

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