C# Selenium 错误:服务器没有响应 url http://localhost:7055
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12321991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium error: No response from server for url http://localhost:7055
提问by Frigik
I'm using Selenium, C#, NUnit to write tests, sometimes I getting below error:-
我正在使用 Selenium、C#、NUnit 来编写测试,有时我会遇到以下错误:-
OpenQA.Selenium.WebDriverException : No response from server for url httр://lоcalhost:7055/hub/session/8dd13f5c-7ca6-4aa6-babc-f0ff6d940f0a/element
OpenQA.Selenium.WebDriverException:服务器没有响应 url httр://lоcalhost:7055/hub/session/8dd13f5c-7ca6-4aa6-babc-f0ff6d940f0a/element
Here is stack trace:
这是堆栈跟踪:
OpenQA.Selenium.WebDriverException : No response from server for url httр://localhost:7055/hub/session/8dd13f5c-7ca6-4aa6-babc-f0ff6d940f0a/element at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\HttpCommandExecutor.cs:line 115 at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\HttpCommandExecutor.cs:line 96 at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Execute(Command commandToExecute) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Firefox\Internal\ExtensionConnection.cs:line 128 at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 795 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 836 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 431 at OpenQA.Selenium.By.<>c__DisplayClass2.b__0(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 102 at OpenQA.Selenium.By.FindElement(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 272 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 289 at
.####.##.#####.#########.#####.ShareServicesTest.CreateShareWidget()
OpenQA.Selenium.WebDriverException :服务器没有响应 url httр://localhost:7055/hub/session/8dd13f5c-7ca6-4aa6-babc-f0ff6d940f0a/element at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\HttpCommandExecutor.cs:line 115 at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) in c:\Projects\WebDriver\trunk\dotnet\src \WebDriver\Remote\HttpCommandExecutor.cs:line 96 at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Execute(Command commandToExecute) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Firefox\Internal\ExtensionConnection.cs :line 128 at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 795 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) in c:\Projects\WebDriver\trunk\dotnet\ src\WebDriver\Remote\RemoteWebDriver.cs:line 836 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 431在 OpenQA.Selenium.By.<>c__DisplayClass2.b__0(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 102 at OpenQA.Selenium.By.FindElement(ISearchContext context)在 c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 272 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) in c:\Projects\WebDriver\trunk\dotnet\src\ WebDriver\Remote\RemoteWebDriver.cs:line 289 at第 289 行第 289 行第 289 行第 289 行Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:在 OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 431 at OpenQA.Selenium.By.<>c__DisplayClass2.b__0(ISearchContext context) in c:\Projects\WebDriver\ trunk\dotnet\src\WebDriver\By.cs:line 102 at OpenQA.Selenium.By.FindElement(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 272 at OpenQA .Selenium.Remote.RemoteWebDriver.FindElement(By by) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 289 atSelenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:在 OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 431 at OpenQA.Selenium.By.<>c__DisplayClass2.b__0(ISearchContext context) in c:\Projects\WebDriver\ trunk\dotnet\src\WebDriver\By.cs:line 102 at OpenQA.Selenium.By.FindElement(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 272 at OpenQA .Selenium.Remote.RemoteWebDriver.FindElement(By by) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 289 at\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 836 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver \Remote\RemoteWebDriver.cs:line 431 at OpenQA.Selenium.By.<>c__DisplayClass2.b__0(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 102 at OpenQA。 Selenium.By.FindElement(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 272 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) in c:\Projects \WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 289 at\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 836 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver \Remote\RemoteWebDriver.cs:line 431 at OpenQA.Selenium.By.<>c__DisplayClass2.b__0(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 102 at OpenQA。 Selenium.By.FindElement(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 272 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) in c:\Projects \WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 289 at\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 431 at OpenQA.Selenium.By.<>c__DisplayClass2.b__0(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src \WebDriver\By.cs: 在 c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs: 在 OpenQA.Selenium.Remote 的 OpenQA.Selenium.By.FindElement(ISearchContext 上下文) 的第 102 行。 RemoteWebDriver.FindElement(By by) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 289 at\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 431 at OpenQA.Selenium.By.<>c__DisplayClass2.b__0(ISearchContext context) in c:\Projects\WebDriver\trunk\dotnet\src \WebDriver\By.cs: 在 c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs: 在 OpenQA.Selenium.Remote 的 OpenQA.Selenium.By.FindElement(ISearchContext 上下文) 的第 102 行。 RemoteWebDriver.FindElement(By by) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 289 atRemote.RemoteWebDriver.FindElement(By by) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 289 atRemote.RemoteWebDriver.FindElement(By by) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 289 at
.####.##.#####.#########.#####.ShareServicesTest.CreateShareWidget()
Code where this error appears:
出现此错误的代码:
Driver.SwitchTo().Frame(frameElement);
var wait = new WebDriverWait(parentContextable.Context.Driver, Timeout);
IWebElement element = wait.Until(d => Driver.FindElement(By.TagName(Tags.Body))); // error in this line
I figured out that this error can be thrown only in this lines of Selenium implementation code:
我发现这个错误只能在这行 Selenium 实现代码中抛出:
private static Response CreateResponse(WebRequest request)
{
Response commandResponse = new Response();
HttpWebResponse webResponse = null;
try
{
webResponse = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
webResponse = (HttpWebResponse)ex.Response;
}
if (webResponse == null)
{
throw new WebDriverException("No response from server for url " + request.RequestUri.AbsoluteUri);
}
else
{ ...
Maybe someone knows why request.GetResponse() returns null, or if it fails why ex.Response also null?
也许有人知道为什么 request.GetResponse() 返回 null,或者如果它失败了为什么 ex.Response 也为 null?
(09.09.2012) Sorry but maybe I didn't provide all information. I'm using FireFox driver, Win7, Selenium 2.25.1. My test fails only sometimes. Test in debug mode fails less often then in Release.
(09.09.2012) 抱歉,也许我没有提供所有信息。我正在使用 FireFox 驱动程序、Win7、Selenium 2.25.1。我的测试只是偶尔失败。调试模式下的测试失败的频率低于发布模式。
HereI found possible reasons why this happen. And if I write such code:
在这里,我找到了发生这种情况的可能原因。如果我写这样的代码:
Driver.SwitchTo().Frame(frameElement);
var wait = new WebDriverWait(parentContextable.Context.Driver, Timeout);
Tread.Sleep(250);
IWebElement element = wait.Until(d => Driver.FindElement(By.TagName(Tags.Body)));
Test runs OK. But Thread.Sleep is bad solution. Maybe somebody could find another, little bit better solution.
测试运行正常。但是 Thread.Sleep 是不好的解决方案。也许有人可以找到另一个更好的解决方案。
回答by MisterJames
Are you using IE? I was getting this until I discovered that I could set the base URL through config on the object. Otherwise, the first page it takes you to is something generated by Selenium, and it seems to miss the cues for the "real" request.
你用的是IE吗?我一直得到这个,直到我发现我可以通过对象上的配置设置基本 URL。否则,它带你进入的第一页是由 Selenium 生成的,它似乎错过了“真实”请求的线索。
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = _baseUrl,
IntroduceInstabilityByIgnoringProtectedModeSettings = true
};
_driver = new InternetExplorerDriver(_ieDriverServerPath, options);
I use that in a TextFixtureSetupmethod in my tests.
我TextFixtureSetup在测试的方法中使用它。
回答by Pani Kumar
Found Following workarounds here:
在此处找到以下解决方法:
https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/1im-LurjK5s
https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/1im-LurjK5s
http://watirmelon.com/2011/10/04/c-avoiding-the-webdriverexception-no-response-from-server-for-url/
http://watirmelon.com/2011/10/04/c-avoiding-the-webdriverexception-no-response-from-server-for-url/
回答by Lucas Oliveira
I had the same problem and solve in this way:
我遇到了同样的问题并以这种方式解决:
a) avoid methods like 'do wity retry' to manipulate IWebElements, because in this way the tests take to many time to run, is unnecessary and tests fails intermittently.
a) 避免使用像“do wity retry”这样的方法来操作 IWebElements,因为这样测试需要很多时间来运行,是不必要的,并且测试会间歇性地失败。
b) downgrade the Firefox version to 5 (maybe from FF 3.6 until 6 works fine, but the new versions of FF throws an intermittent exception like 'No response from hub/session...'
b) 将 Firefox 版本降级到 5(可能从 FF 3.6 到 6 工作正常,但新版本的 FF 会引发间歇性异常,例如“集线器/会话无响应...”
c) if you need to handle elements in your test that is loaded via Ajax on page, be sure to provide a js function that you can stop element load, so you should call this function from WebDdriver before FindElement and do what you want.
c) 如果你的测试中需要处理页面上通过 Ajax 加载的元素,一定要提供一个可以停止元素加载的 js 函数,所以你应该在 FindElement 和do what you want.

