org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055

Selenium 和 Firefox 版本不兼容的問題解決
在網上找了很久,雖然都說是版本問題,建議降低 Firefox 的版本,或者是升級 Selenium的版本,照着他們的匹配方案,都沒有解決我的問題,自己在mvnrepository 上搜索了最新的 selenium-Java

  1. Firefox 版本:39.0.3 ,感謝自己沒更新,不知道最新的 43 能不能兼容 selenium的52版。用過的小夥伴麻煩告知一聲
    這裏寫圖片描述

  2. selenium-Java 版本:2.52.0

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.52.0</version>
</dependency>

mvnrepository 的鏈接地址爲: mvnrepository
截個圖,看看版本信息
這裏寫圖片描述


下面是代碼,驗證我說版本是不是成功匹配

package selenium;

import java.io.IOException;

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

public class FirefoxTest {
    public static void main(String[] args) throws IOException {
        // 設置 Firefox 的路徑
        System.setProperty("webdriver.firefox.bin",
                "D:\\rj\\work\\firefox\\firefox.exe");

        // 創建一個 FirefoxDriver 的接口,用於連接 Firefox
        // 創建一個 Firefox 的瀏覽器實例
        WebDriver driver = new FirefoxDriver();

        // 讓瀏覽器訪問 Baidu
        driver.get("http://www.baidu.com");
        // 用下面代碼也可以實現
        // driver.navigate().to("http://www.baidu.com");

        // 獲取 網頁的 title
        System.out.println("1 Page title is: " + driver.getTitle());

        // 關閉瀏覽器
        driver.quit();

    }
}

沒設置 pause 時間,手快地截了張圖
這裏寫圖片描述

好了~~~~看到最後的都是 真愛—-〉代碼。
selenium 2.52.0 ==〉Firefox 39.0.3

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章