Selenium WebDriver loses connection to web page

妖精的绣舞 提交于 2021-01-27 12:45:27

问题


I'm executing an automated test with Selenium ChromeDriver against a form on a web page. When I click the Submit button on the form, my WebDriver is losing connection to the browser/page/components, etc. Any subsequent action against the page objects or the browser results in timeouts because it no longer has a connection. It's as if the submit causes the underlying connection to break.

This is the error I get and it's a similar error no matter if I'm trying to click a page object, manipulate the browser, read any attributes, etc.

The HTTP request to the remote WebDriver server for URL:

http://localhost:5621/session/270f189e4b90085032409e475c3a3079/url timed out after 60 seconds.

additional information: at System.Net.HttpWebRequest.GetResponse()\r\n at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)

Is there a way to re-establish(refresh) a Selenium WebDriver connection or best option, to prevent the connection from getting broken? The web app developers state that they don't know of anything the app would be doing that would cause it.

There is nothing special about the code - same code I execute for 100s of tests. submitButton.Click(); where submitButton uses a css locator. Again, I'm unable to manipulate any page objects at all anymore, as if the browser was shut down even though it's still up and open.

code is a simple button click

driver.FindElement(By.Id("btnLogin")).Click();


回答1:


In my case, my button's type was "submit", not button. I don't know the reason that it would make it appear that all connection was lost with the page and page objects, but the fix was to change the .Click() to .Submit().

change this line

driver.FindElement(By.Id("btnLogin")).Click();

to

driver.FindElement(By.Id("btnLogin")).Submit();

It seems like you should get a Selenium exception on the Click() rather than nothing being accessible but this made it execute properly.



来源:https://stackoverflow.com/questions/53488133/selenium-webdriver-loses-connection-to-web-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!