【问题标题】:No response from server for url - Selenium WebDriver (C#) [duplicate]服务器没有响应 url - Selenium WebDriver (C#) [重复]
【发布时间】:2013-03-15 05:05:36
【问题描述】:

更新:

我在更新到 2.29 后遇到了同样的问题,它的前后不一致是令人沮丧的部分。

更新结束:

Selenium WebDriver 2.25 版本。 浏览器:FF(17.0.1版本)&IE(8)

最烦人/让我发疯的一件事是关于过时的元素,我仍然不确定我的测试用例如何一直运行通过;有时我的测试用例通过,有时失败,我正在使用 CSSSelector 查找元素,但我的测试用例仍然开/关失败....

这是我用来查找元素的内容。

这是我的 C# 代码

public class WebDriverUtil
{
       public static IWebDriver driver = StartBrowser();
       private static FirefoxProfile _ffp;
       private static IWebDriver _driver;

        private static IWebDriver StartBrowser()
        { 
            switch (Common.BrowserSelected)
            {
                case "ff":
                    _ffp = new FirefoxProfile();
                    _ffp.AcceptUntrustedCertificates = true;
                    _driver = new FirefoxDriver(_ffp);
                    break;
                case "ie":                    
                    var options = new InternetExplorerOptions();
                    options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                    _driver = new InternetExplorerDriver(options);
                    _driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(2));
                    break;
                case "chrome":
                    //_driver = new ChromeDriver();
                    break;
            } 
            return _driver;
        }    

        public static IWebElement WaitForElement(By by)
        {
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
            return wait.Until(drv => drv.FindElement(by));
        }
}


public class TestCaseEmployee: WebDriverUtil
{
   public static bool EmployeeCase()
   {
      //....
      WaitForElement(By.LinkText("Select All Employee")).Click(); //<<< see error below
   }
}

//错误信息:

Test 'M:TestCases.TestCaseEmployee' failed: No response from server for url http://localhost:7056/hub/session/79b742cf-e1dc-4016-bdbb-c2de93cd8fa4/element
    OpenQA.Selenium.WebDriverException: No response from server for url http://localhost:7056/hub/session/79b742cf-e1dc-4016-bdbb-c2de93cd8fa4/element
    at OpenQA.Selenium.Support.UI.DefaultWait`1.PropagateExceptionIfNotIgnored(Exception e)
    at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)

【问题讨论】:

  • 提及您在哪个浏览器中收到此错误并提供详细信息。
  • 你为什么运行旧版本的 Selenium?什么版本的 IE & FF?
  • FF(17.0.1版本)&IE(8)
  • 不,不是,它是 v2.29.1: code.google.com/p/selenium/downloads/list ....考虑到 FF 17 support 直到 v2.27 才出现,至少升级您的 Selenium 版本并重试。这包括both 绑定和 IE 驱动程序,自 v2.25 以来它已经有了一些改进。
  • 不要使用主网站,我给你的上面的链接是指向源代码存储库的直接链接——它保持最新,而网站不是。不,最新的 .NET 版本是 2.29.1

标签: selenium-webdriver


【解决方案1】:

我遇到了同样的问题,用这种方法解决:

a) 避免使用“do wity retry”之类的方法来操作 IWebElements,因为这样测试需要花费很多时间来运行,这是不必要的,并且测试会间歇性地失败。

b) 将 Firefox 版本降级到 5(可能从 FF 3.6 到 6 可以正常工作,但新版本的 FF 会引发间歇性异常,例如“集线器/会话无响应...”

c) 如果您需要在页面上处理通过 Ajax 加载的测试中的元素,请务必提供一个可以停止元素加载的 js 函数,因此您应该在 FindElement 之前从 WebDdriver 调用此函数并执行您的操作想要。

【讨论】:

  • 如果您可以完全对两个问题发布相同的答案,则表明这些问题是重复的。而不是发布第二个答案,您应该标记(或投票)作为重复关闭。
猜你喜欢
  • 2017-01-09
  • 2012-09-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-09
  • 2020-11-12
  • 1970-01-01
  • 1970-01-01
  • 2014-06-04
相关资源
最近更新 更多