简体   繁体   English

org.openqa.selenium.WebDriverException:java.io.IOException:使用GeckoDriver调用getCookies()时,连接上的流意外结束

[英]org.openqa.selenium.WebDriverException: java.io.IOException: unexpected end of stream on Connection while invoking getCookies() with GeckoDriver

I keep getting an error like this 我不断收到这样的错误

org.openqa.selenium.WebDriverException: java.io.IOException: unexpected end of stream on Connection{localhost:13080, proxy=DIRECT hostAddress=localhost/127.0.0.1:13080 cipherSuite=none protocol=http/1.1}

when trying to read cookies from firefox. 尝试从Firefox读取Cookie时。 The exact same action can be performed with chrome with no problem. 使用chrome可以执行完全相同的操作,而不会出现问题。 Port used is pretty random, anytime I start a new test I get a new port assigned as well. 使用的端口是非常随机的,每当我开始新的测试时,我也会分配一个新的端口。 Should specifying another port be able to do something here? 指定其他端口是否应该可以在此处执行某些操作? The line of code that produces it is: 产生它的代码行是:

driver.manage().getCookies().forEach(cookie -> System.out.println(cookie.toString()));

I wonder if it's an initialization problem with firefox and setting some value will get me past it. 我想知道这是否是firefox的初始化问题,设置一些值会使我摆脱它。 The initialization I do is just this: 我要做的初始化就是这样:

FirefoxOptions Foptions = new FirefoxOptions();
Foptions.setBinary("/home/user/firefox/firefox");
Foptions.setCapability("marionette", true);
driver =  new FirefoxDriver(Foptions);

It is tough to analyze the error without the error stack trace. 没有错误堆栈跟踪就很难分析错误。 The error stack trace would have helped immencely to debug the issue. 错误堆栈跟踪本可以极大地帮助调试问题。

However this error message... 但是,此错误消息...

org.openqa.selenium.WebDriverException: java.io.IOException: unexpected end of stream on Connection{localhost:13080, proxy=DIRECT hostAddress=localhost/127.0.0.1:13080 cipherSuite=none protocol=http/1.1}

...implies that the java.io.IOException was raised when you tried to invoke getCookies() . ...暗示当您尝试调用getCookies()时引发了java.io.IOException

Your main issue can be one of the following: 您的主要问题可能是以下问题之一:

  • Reason A : When you invoked driver.manage().getCookies() though apparently it seems the HTML DOM have loaded but still some javaScript / Ajax Calls are active setting the cookies. 原因A :显然,当您调用driver.manage().getCookies()HTML DOM已加载,但仍在激活某些cookie的javaScript / Ajax调用中。
  • Solution : Induce WebDriverWait for an element to be clickable as follows: 解决方案促使 WebDriverWait使元素可单击 ,如下所示:

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#btn_download"))).click() 
  • Reason B : As per java.io.IOException: unexpected end of stream on Connection in android it may be possible that the server throwed an error and shut down as the parsing of the request was in progress. 原因B :根据java.io.IOException:android中Connection上流的意外结束,可能是服务器在解析请求时抛出错误并关闭。

  • Solution : Cross check if you are able to access the elements within the webpage without mingling with the cookies. 解决方案 :交叉检查是否能够访问网页中的元素,而不会与Cookie混合在一起。
  • Reason C : Another reason can be the port being used by geckodriver/marionette is being used by some other application/service . 原因C :另一个原因可能是geckodriver / marionette正在使用的端口被其他一些应用程序/服务所使用
  • Solution : Freeup the ports used by GeckoDriver/Marionette 解决方案 :释放GeckoDriver / Marionette使用的端口

在硒3.12.0及更高版本上使用driver.manage()。getCookies()方法时,我遇到了同样的问题,将硒版本降级为3.11.0,并且工作正常,此问题已在最新版本中引入。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Exception in thread “main” org.openqa.selenium.WebDriverException: java.io.IOException: Unable to parse URL: http://localhost:?????/session - Exception in thread “main” org.openqa.selenium.WebDriverException: java.io.IOException: Unable to parse URL: http://localhost:?????/session org.openqa.selenium.WebDriverException:使用Selenium Java和Webdriver时连接被拒绝(Linux头没有Xvfb) - org.openqa.selenium.WebDriverException: connection refused while using Selenium Java and webdriver (linux headless with Xvfb) org.openqa.selenium.WebDriverException: java.net.ConnectException: 无法使用 GeckoDriver 和 Selenium 连接到 localhost/0:0:0:0:0:0:0:1:1941 - org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941 with GeckoDriver and Selenium org.openqa.selenium.WebDriverException:[异常…“组件未初始化”错误使用 GeckoDriver 和 Tor 浏览器与 Selenium ZD52387880E1EA22817A7Z2D3759213891 - org.openqa.selenium.WebDriverException: [Exception… “Component not initialized” error using GeckoDriver and Tor browser with Selenium Java java.io.IOException:Connection jsoup上的流意外结束 - java.io.IOException: unexpected end of stream on Connection jsoup org.openqa.selenium.WebDriverException: java.net.ConnectException: 无法使用 GeckoDriver Firefox 和 Selenium 连接到 localhost/0:0:0:0:0:0:0 - org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0 using GeckoDriver Firefox and Selenium java.io.IOException:连接上的流意外结束(Android,jsoup) - java.io.IOException: unexpected end of stream on Connection (Android, jsoup) 错误“org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/” with GeckoDriver 和 Firefox - error“ org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/” with GeckoDriver and Firefox java.io.IOException:意外的流结束 - java.io.IOException: unexpected end of stream org.openqa.selenium.WebDriverException:通过Selenium v​​3.4.0和geckodriver-v0.20.1启动Firefox浏览器45.0.1时,连接被拒绝 - org.openqa.selenium.WebDriverException: connection refused while launching Firefox Browser 45.0.1 through Selenium v3.4.0 and geckodriver-v0.20.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM