gpt4 book ai didi

c# - Selenium ChromeDriver 管理超时

转载 作者:行者123 更新时间:2023-12-04 10:32:43 24 4
gpt4 key购买 nike

ChromeOptions options = new ChromeOptions();

options.PageLoadStrategy = PageLoadStrategy.Eager;

string[] options_list = new string[]
{
"start-maximized",
"enable-automation",
//"--headless",
"--no-sandbox",
"--disable-infobars",
"--disable-dev-shm-usage",
"--disable-gpu",
"enable-features=NetworkServiceInProcess"
};

options.AddArguments(options_list);

using (IWebDriver driver = new ChromeDriver(options))
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromMinutes(5));

driver.Navigate().GoToUrl(url);


wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Name("lgin"))).Click();

// After lgin clicked
// Page may load for 3 to 5 minutes due to huge data processing

wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("Img2"))).Click();
}

在 3 到 5 分钟的等待期间,我总是会遇到下面的异常错误。

对 URL http://localhost:50696/session/b8dbc3609bdb0d779c81886942342b6d/element/1fc37ce8-a8a0-4a51-84ed-18828edf7b46/click 的远程 WebDriver 服务器的 HTTP 请求60 秒后超时。

我尝试添加以下代码:
driver.Manage().Timeouts().PageLoad.Add(TimeSpan.FromMinutes(5));
driver.Manage().Timeouts().ImplicitWait.Add(TimeSpan.FromMinutes(5));

但是超时时间还是60秒

最佳答案

您是否尝试过 WebDriverWait

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

您很可能遇到了这个问题: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4874

Each driver class has a constructor overload that allows you to set the timeout for each command. Here is an example for the FirefoxDriver to set the command timeout to 5 minutes:


IWebDriver driver = new FirefoxDriver(new FirefoxBinary(), null, TimeSpan.FromMinutes(5));

You can find similar constructor overloads for InternetExplorerDriver, ChromeDriver, and RemoteWebDriver.

关于c# - Selenium ChromeDriver 管理超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60332986/

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