簡體   English   中英

Selenium Webdriver:Ubuntu14.04中的連接被拒絕(連接被拒絕)錯誤

[英]Selenium webdriver: Connection refused (connection refused) error in Ubuntu14.04

我正在嘗試在Ubuntu14.04中設置Selenium webdriver3.4。 運行Selenium腳本時,出現HttpHostConnectionException錯誤。 請在下面找到我使用的腳本和錯誤:

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class SampleTest {
    WebDriver driver;
  @BeforeTest
  public void f() {
      System.setProperty("webdriver.gecko.driver","/usr/local/bin/geckodriver");
      driver = new FirefoxDriver(); 
       }

     @Test
     public void approvelisting() 
     {
        driver.get("https://<domain name>/");
        driver.manage().timeouts().implicitlyWait(500, TimeUnit.SECONDS);
  }
}

[RemoteTestNG]檢測到TestNG版本6.12.0 1507297197197 geckodriver INFO geckodriver 0.19.0 1507297197226 geckodriver INFO偵聽127.0.0.1:13663失敗的配置:@BeforeTest f org.openqa.selenium.WebDriverException:org.apache.http.conn.HttpHostConnectException:連接到localhost:13663 [localhost / 127.1.0.0]失敗:連接被拒絕(連接被拒絕)構建信息:版本:'3.4.0',修訂版本:'未知',時間:'未知'系統信息:主機:'admin- coddletech'',ip:'127.0.0.1',os.name:'Linux',os.arch:'amd64',os.version:'3.16.0-30-generic',java.version:'1.8.0_141'驅動程序信息:driver.version:FirefoxDriver

請幫助我排除此異常

我認為您的代碼是正確的,似乎您的本地主機未正確安裝。

它正在我的系統中運行,並且還使用其他URL運行。 我嘗試與另一個相同的代碼,它工作正常。 更改Localhost的端口號,然后嘗試

這是我的代碼:

public class Stackoverflow_demo {

    WebDriver driver;
      @BeforeTest
      public void f() {
          driver = new FirefoxDriver(); 
           }

         @Test
         public void approvelisting() 
         {
            driver.get("http://127.0.0.1:8080/");
            driver.manage().timeouts().implicitlyWait(500, TimeUnit.SECONDS);
      }
}

如果127.0.0.1 localhost有其他IP,請確保在/etc/hosts輸入了127.0.0.1 localhost ,然后將其刪除。 連接到localhost:13663 [localhost/127.1.0.0]表示localhost出於某種原因轉到127.1.0.0而不是127.0.0.1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM