[英]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: 您的主要问题可能是以下问题之一:
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上流的意外结束,可能是服务器在解析请求时抛出错误并关闭。
在硒3.12.0及更高版本上使用driver.manage()。getCookies()方法时,我遇到了同样的问题,将硒版本降级为3.11.0,并且工作正常,此问题已在最新版本中引入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.