【问题标题】:Selenium webdriver: Connection refused (connection refused) error in Ubuntu14.04Selenium webdriver:Ubuntu14.04中的连接被拒绝(连接被拒绝)错误
【发布时间】:2018-03-18 09:56:02
【问题描述】:

我正在尝试在 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 .版本:'1.8.0_141' 驱动信息:driver.version:FirefoxDriver

请帮助我解决此异常

【问题讨论】:

  • 您是否尝试打开其他网址?
  • 请确保您在/etc/hosts 中有127.0.0.1 localhost 的条目,如果本地主机有任何其他IP,然后将其删除。 Connect to localhost:13663 [localhost/127.1.0.0] 表示 localhost 出于某种原因转到 127.1.0.0 而不是 127.0.0.1
  • 感谢@Tarun 成功了。

标签: java selenium


【解决方案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

【讨论】:

    【解决方案2】:

    我认为您的代码是正确的,看来您的本地主机设置不正确。

    它在我的系统中运行,并且还使用不同的 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);
          }
    }
    

    【讨论】:

    • 是的。它正在工作。非常感谢@Tarun Lalwani。我在这个问题上挣扎了一个多星期
    • 好的,我的回答对您有帮助吗?请点赞,很高兴您的问题得到解决。
    猜你喜欢
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多