Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

c# - Selenium error: No response from server for url http://localhost:7055

I'm using Selenium, C#, NUnit to write tests, sometimes I getting below error:-

OpenQA.Selenium.WebDriverException : No response from server for 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:ProjectsWebDriverrunkdotnetsrcWebDriverRemoteHttpCommandExecutor.cs:line 115 at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) in c:ProjectsWebDriverrunkdotnetsrcWebDriverRemoteHttpCommandExecutor.cs:line 96 at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Execute(Command commandToExecute) in c:ProjectsWebDriverrunkdotnetsrcWebDriverFirefoxInternalExtensionConnection.cs:line 128 at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in c:ProjectsWebDriverrunkdotnetsrcWebDriverRemoteRemoteWebDriver.cs:line 795 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) in c:ProjectsWebDriverrunkdotnetsrcWebDriverRemoteRemoteWebDriver.cs:line 836 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id) in c:ProjectsWebDriverrunkdotnetsrcWebDriverRemoteRemoteWebDriver.cs:line 431 at OpenQA.Selenium.By.<>c__DisplayClass2.b__0(ISearchContext context) in c:ProjectsWebDriverrunkdotnetsrcWebDriverBy.cs:line 102 at OpenQA.Selenium.By.FindElement(ISearchContext context) in c:ProjectsWebDriverrunkdotnetsrcWebDriverBy.cs:line 272 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) in c:ProjectsWebDriverrunkdotnetsrcWebDriverRemoteRemoteWebDriver.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:

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?

(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.

Here I 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...