Selenium ChromeDriver-60秒后,HTTP到远程WebDriver服务器的URL请求超时

时间:2019-05-29 08:43:38

标签: c# selenium-webdriver nunit

我正在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();
    }

如您所见,当我跑步时,我尝试将超时时间增加到所有地方2分钟

Driver.Navigate().GoToUrl(url);

针对我得到的页面

OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL timed out after 60 seconds.

该页面的加载时间超过60秒,那么如何增加60秒?

1 个答案:

答案 0 :(得分:1)

您需要增加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));