【问题标题】:Selenium WebDriver SetPageLoadTimeout does not work in c#?Selenium WebDriver SetPageLoadTimeout 在 c# 中不起作用?
【发布时间】:2014-09-30 19:34:24
【问题描述】:

我一直在 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.

【问题讨论】:

  • “超时”,用什么?请完整的错误和堆栈跟踪。
  • 我编辑了帖子并添加了异常消息。我无法添加整个堆栈跟踪,因为测试是通过没有 Visual Studio 的远程服务器上的应用程序运行的,并且该服务器是唯一一个足够慢以获取此异常的服务器。修复了“超时”:D

标签: c# selenium timeout pageload selenium-chromedriver


【解决方案1】:

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

  • TimeSpan.FromMinutes(4) --> 4 分钟后超时

【讨论】:

  • 嗨。 Tnx 为您解答,但我不清楚,这是使用 Chrome 或 Firefox 的 Firefox 驱动程序配置文件,因为 Firefox 工作正常......
【解决方案2】:

试试这个,对我有用

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

            IWebDriver driver = new ChromeDriver(options);

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

【讨论】:

    猜你喜欢
    • 2022-11-10
    • 2021-11-21
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多