Selenium ChromeDriver - URL 对远程 WebDriver 服务器的 HTTP 请求在 60 秒后超时
Selenium ChromeDriver - the HTTP request to the remote WebDriver server for URL timed out after 60 seconds
我在 nunit 测试中使用 ChromeDriver 来测试复杂页面是否加载:
public ChromeDriver Driver { get; private set; }
[OneTimeSetUp]
public void Setup()
{
ChromeOptions co = new ChromeOptions{};
co.AddArgument("no-sandbox");
Driver = new ChromeDriver( co) ;
Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(120);
Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(120);
Driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(120);
Driver.Manage().Window.Maximize();
}
如您所见,当我 运行
Driver.Navigate().GoToUrl(url);
针对我得到的页面
OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL timed out after 60 seconds.
页面加载时间确实超过 60 秒,那么如何增加 60 秒?
您需要在 RemoteWebDriver 中增加 DefaultCommandTimeout
。您可以使用 ChromeDriver(ChromeDriverService, ChromeOptions, TimeSpan)
或 ChromeDriver(string, ChromeOptions, TimeSpan)
重载
ChromeOptions co = new ChromeOptions{};
Driver = new ChromeDriver("path to ChromeDriver.exe", co, TimeSpan.FromSeconds(120));
// or
Driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), co, TimeSpan.FromSeconds(120));
我在 nunit 测试中使用 ChromeDriver 来测试复杂页面是否加载:
public ChromeDriver Driver { get; private set; }
[OneTimeSetUp]
public void Setup()
{
ChromeOptions co = new ChromeOptions{};
co.AddArgument("no-sandbox");
Driver = new ChromeDriver( co) ;
Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(120);
Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(120);
Driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(120);
Driver.Manage().Window.Maximize();
}
如您所见,当我 运行
Driver.Navigate().GoToUrl(url);
针对我得到的页面
OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL timed out after 60 seconds.
页面加载时间确实超过 60 秒,那么如何增加 60 秒?
您需要在 RemoteWebDriver 中增加 DefaultCommandTimeout
。您可以使用 ChromeDriver(ChromeDriverService, ChromeOptions, TimeSpan)
或 ChromeDriver(string, ChromeOptions, TimeSpan)
重载
ChromeOptions co = new ChromeOptions{};
Driver = new ChromeDriver("path to ChromeDriver.exe", co, TimeSpan.FromSeconds(120));
// or
Driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), co, TimeSpan.FromSeconds(120));