Selenium WebDriver SetPageLoadTimeout在c#中不起作用?

时间:2014-08-07 14:02:07

标签: c# selenium timeout pageload selenium-chromedriver

我一直在使用Chrome中的Selenium网络驱动程序,无法设置默认的网页加载等待时间。测试较慢的网页时,驱动程序会在60秒后超时。

我尝试了两种方法:

1

TimeSpan PageLoad = new TimeSpan(0, 0, 120);
driver = new ChromeDriver(ChromeDriverPath);
driver.Manage().Timeouts().SetPageLoadTimeout(PageLoad);

2:

public static void WaitForPageLoading()
{         
WebDriverWait wait = new WebDriverWait(iwdCurrentlyUsedDriver,     TimeSpan.FromSeconds(120));
 wait.Until<bool>((d) =>
  {
   try
   {
   string test = ((OpenQA.Selenium.IJavaScriptExecutor)EngineGloblalVariables.iwdCurrentlyUsedDriver).ExecuteScript("return document.readyState").ToString();
    if (test.Equals("complete"))
         return true;
    return false;
    }
    catch
    {                   
     return false;
    }
  });
   }

在将驱动程序导航到页面后使用第二个解决方案。在使用Firefox时,我成功地使用了第二种解决方案,但Chrome在60秒后仍然超时。是否有其他方法可以设置或更改页面加载的默认超时?

编辑:

异常消息:

The HTTP request to the remote WebDriver server for URL
http://localhost:14545/session/4e0f1edcbc87d06360b6c89a06574476/buttonup timed out after
60 seconds.

2 个答案:

答案 0 :(得分:0)

请使用此。 driver = new FirefoxDriver(new FirefoxBinary(),firefoxProfile,TimeSpan.FromMinutes(4));

  • TimeSpan.FromMinutes(4) - &gt;超时4分钟

答案 1 :(得分:0)

尝试一下,为我工作

            var options = new ChromeOptions();
            options.PageLoadStrategy = PageLoadStrategy.None;

            IWebDriver driver = new ChromeDriver(options);

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromMinutes(3));