简体   繁体   English

Selenium 3.7:geckodriver:WebDriverException:org.apache.http.conn.HttpHostConnectException连接被拒绝

[英]Selenium 3.7 : geckodriver : WebDriverException: org.apache.http.conn.HttpHostConnectException Connection Refused

Recently I upgraded to Selenium 3.7. 最近,我升级到Selenium 3.7。

Code: 码:

import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.firefox.FirefoxDriver;


public static void main (String args[]){

    System.setProperty("webdriver.gecko.driver", 
    "/usr/local/bin/geckodriver");      
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.google.com");
    driver.quit();
  }

Included Library: 包括的图书馆:

selenium-java-3.7.1/selenium-server-standalone-3.7.1.jar selenium-java-3.7.1 / selenium-server-standalone-3.7.1.jar

selenium-java-3.7.1/libs/httpcore-4.4.6.jar selenium-java-3.7.1 / libs / httpcore-4.4.6.jar

selenium-java-3.7.1/libs/httpclient-4.5.3.jar selenium-java-3.7.1 / libs / httpclient-4.5.3.jar

selenium-java-3.7.1/libs/guava-23.0.jar selenium-java-3.7.1 / libs / guava-23.0.jar

selenium-java-3.7.1/libs/gson-2.8.2.jar selenium-java-3.7.1 / libs / gson-2.8.2.jar

selenium-java-3.7.1/libs/commons-logging-1.2.jar selenium-java-3.7.1 / libs / commons-logging-1.2.jar

selenium-java-3.7.1/libs/commons-exec-1.3.jar selenium-java-3.7.1 / libs / commons-exec-1.3.jar

selenium-java-3.7.1/libs/commons-codec-1.10.jar selenium-java-3.7.1 / libs / commons-codec-1.10.jar

selenium-java-3.7.1/libs/byte-buddy-1.7.5.jar selenium-java-3.7.1 / libs / byte-buddy-1.7.5.jar

selenium-java-3.7.1/client-combined-3.7.1.jar selenium-java-3.7.1 / client-combined-3.7.1.jar

selenium-java-3.7.1/client-combined-3.7.1-sources.jar selenium-java-3.7.1 / client-combined-3.7.1-sources.jar

System environment: 系统环境:

Firefox 56.0.2 Firefox 56.0.2

Java 1.8 Java 1.8

selenium-java-3.7.1 硒java-3.7.1

selenium-server-standalone-3.7.1 硒服务器独立3.7.1

geckodriver - v0.19.1 壁虎驱动程序-v0.19.1

Error trace log: 错误跟踪日志:

Usage: 用法:

/usr/local/bin/geckodriver [OPTIONS] /usr/local/bin/geckodriver: Unknown option --port=8970 Exception in thread "main" org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8970 [localhost/0:0:0:0:0:0:0:1, localhost/fe80:0:0:0:0:0:0:1%1] failed: Connection refused (Connection refused) Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z' System info: host: 'Maggies-MacBook-Pro-2.local', ip: '192.168.1.6', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_121' Driver info: driver.version: FirefoxDriver / usr / local / bin / geckodriver [选项] / usr / local / bin / geckodriver:未知选项--port = 8970线程“主”中的异常org.openqa.selenium.WebDriverException:org.apache.http.conn.HttpHostConnectException :连接到localhost:8970 [localhost / 0:0:0:0:0:0:0:1,localhost / fe80:0:0:0:0:0:0:1%1]失败:连接被拒绝(拒绝连接)构建信息:版本:'3.7.1',修订版本:'8a0099a',时间:'2017-11-06T21:07:36.161Z'系统信息:主机:'Maggies-MacBook-Pro-2.local' ,ip:'192.168.1.6',os.name:'Mac OS X',os.arch:'x86_64',os.version:'10 .12.6',java.version:'1.8.0_121'驱动程序信息:驱动程序.version:FirefoxDriver

Any idea would be appreciated. 任何想法将不胜感激。 Thank you. 谢谢。

Update after trying Debanjan suggestion: 尝试Debanjan建议后进行更新:

Code: 码:

public static void main (String args[]){
    System.out.println("Debug 1");
    System.setProperty("webdriver.gecko.driver", 
    "/Users/maggie/Documents/ToolsQA/Libs/geckodriver");    
    System.out.println("Debug 2");
    WebDriver driver = new FirefoxDriver();
    System.out.println("Debug 3");
    driver.get("http://www.google.com");
    driver.quit();
  }

Include Library: 包含库:

selenium-server-standalone-3.7.1.jar selenium-server-standalone-3.7.1.jar

System Environment: 系统环境:

Firefox 56.0.2 Firefox 56.0.2

Java 1.8 Java 1.8

selenium-java-3.7.1 硒java-3.7.1

selenium-server-standalone-3.7.1 硒服务器独立3.7.1

geckodriver 0.19.1 壁虎起子0.19.1

Mac OS X', os.arch: 'x86_64', os.version: '10.12.6' Mac OS X”,os.arch:“ x86_64”,os.version:“ 10.12.6”

Error trace log: 错误跟踪日志:

Debug 1 Debug 2 Starting ChromeDriver 2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2) on port 2198 Only local connections are allowed. 调试1调试2在端口2198上启动ChromeDriver 2.33.506106(8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2)仅允许本地连接。 Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. 线程“主”中的异常org.openqa.selenium.WebDriverException:等待驱动程序服务器启动时超时。 Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z' System info: host: 'Maggies-MacBook-Pro-2.local', ip: '192.168.1.6', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_121' Driver info: driver.version: ChromeDriver at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192) at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:181) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:168) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) a 内部版本信息:版本:'3.7.1',版本:'8a0099a',时间:'2017-11-06T21:07:36.161Z'系统信息:主机:'Maggies-MacBook-Pro-2.local',ip: '192.168.1.6',操作系统名称:'Mac OS X',os.arch:'x86_64',os.version:'10 .12.6',java.version:'1.8.0_121'驱动程序信息:driver.version:位于org.openqa.selenium的org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)的org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192)的ChromeDriver。 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)上的remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java: 219)在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:142)在org.openqa.selenium.chrome.ChromeDriver。(ChromeDriver.java:181)在org.openqa.selenium.chrome.ChromeDriver。( ChromeDriver.java:168),位于org.openqa.selenium.chrome.ChromeDriver。(ChromeDriver.java:123)a t AutomationFrameWork.FirstTestCase.main(FirstTestCase.java:13) Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [ http://localhost:2198/status] to be available after 20005 ms at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100) at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187) ... 9 more Caused by: java.util.concurrent.TimeoutException at java.util.concurrent.FutureTask.get(FutureTask.java:205) at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147) at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75) ... 10 more t AutomationFrameWork.FirstTestCase.main(FirstTestCase.java:13)由以下原因引起:org.openqa.selenium.net.UrlChecker $ TimeoutException:超时等待[ http:// localhost:2198 / status]在20005 ms之后可用org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)上的org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)... 9更多原因:java.util org.openqa.selenium.net上com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147)上的java.util.concurrent.FutureTask.get(FutureTask.java:205)上的.concurrent.TimeoutException .UrlChecker.waitUntilAvailable(UrlChecker.java:75)...还有10个

The error WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8970 can occur due to different reasons. 错误WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8970由于不同的原因,可能会发生WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8970的错误。 More over there is a discrepency in your Included Library list as selenium-server-standalone-3.7.1.jar is never a part of downloaded selenium-java-3.7.1.zip . 此外,您的“ Included Library列表中存在差异,因为selenium-server-standalone-3.7.1.jar绝不是下载的selenium-java-3.7.1.zip的一部分。

Try out the steps mentioned below: 尝试以下提到的步骤:

  • From the Included Library list remove all the jars . 从“ Included Library列表中删除所有jars
  • Download and Add only selenium-server-standalone-3.7.1.jar from this link or from this link 从此this link或从此this link Download Add selenium-server-standalone-3.7.1.jar
  • Ensure that /etc/hosts on your system contains the following entry : 确保系统上的/etc/hosts包含以下条目:

     1 127.0.0.1 localhost.localdomain localhost 
  • Run CCleaner Tool to wipe away all the OS chores from your system. 运行CCleaner Tool清除系统中所有的OS杂项。

  • You can opt for a System Reboot . 您可以选择System Reboot
  • Execute your Test . 执行Test

I tried with the same versions without any problem. 我尝试了相同的版本,没有任何问题。

If the path to the geckodriver: 如果壁虎驱动程序的路径:

System.setProperty("webdriver.gecko.driver", 
    "/usr/local/bin/geckodriver"); 

is correct, make sure that the geckodriver is executable for the user that execute the code: 是正确的,请确保执行代码的用户的geckodriver是可执行的:

chmod +x geckodriver

After doing some research, I manage to resolve this problem. 经过研究后,我设法解决了这个问题。

The error is due to the 127.0.0.1 map to localhost.com in etc/hosts. 该错误是由于在etc / hosts中将127.0.0.1映射到localhost.com引起的。 Edited: 127.0.0.1 localhost 编辑:127.0.0.1本地主机

I think you are missing the .exe extension. 我认为您缺少.exe扩展名。 Your path should be like this 你的路应该是这样的

System.setProperty("webdriver.gecko.driver", 
    "/usr/local/bin/geckodriver.exe");

暂无
暂无

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

相关问题 org.apache.http.conn.HttpHostConnectException:拒绝连接到http:// localhost - org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused 错误:请求中的异常:org.apache.http.conn.HttpHostConnectException:与http:// ********:80的连接被拒绝 - ERROR:Exception in request: org.apache.http.conn.HttpHostConnectException: Connection to http://********:80 refused Android Studio错误org.apache.http.conn.HttpHostConnectException:拒绝与http://10.0.2.2:8080的连接 - Android Studio error org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused org.apache.http.conn.HttpHostConnectException:连接到127.0.0.1:7055 [/127.0.0.1]失败:连接被拒绝:connect - org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7055 [/127.0.0.1] failed: Connection refused: connect org.apache.http.conn.HttpHostConnectException:连接到127.0.0.1:7055 - org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7055 线程“ main” org.apache.http.conn.HttpHostConnectException中的异常:连接到//失败:连接超时:connect - Exception in thread “main” org.apache.http.conn.HttpHostConnectException: Connect to // failed: Connection timed out: connect 在jmeter中收到错误“响应代码:非HTTP响应代码:org.apache.http.conn.HttpHostConnectException” - Getting an error “Response code: Non HTTP response code: org.apache.http.conn.HttpHostConnectException” in jmeter 从Eclipse访问URL时获取org.apache.http.conn.HttpHostConnectException - Getting org.apache.http.conn.HttpHostConnectException while accessing a URL from Eclipse GitLab Runner 不一致:exec-maven-plugin:1.6.0:java org.apache.http.conn.HttpHostConnectException - GitLab Runner Inconsistency: exec-maven-plugin:1.6.0:java org.apache.http.conn.HttpHostConnectException 引起:com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException:org.apache.http.conn.HttpHostConnectException:微服务 - Caused by: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Microservices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM