IEDE+JAVA+Selenium,配置了chromedriver2.40的環境,運行時仍然是2.9問題解決

      如圖所示,運行時打開瀏覽器出現data,這意味着chromedriver與selenium版本不符。隨着瀏覽器更新,對應版本會一直更新。用的時候搜一下即可。文章末尾提供了驅動器的下載地址。

 異常信息:Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.SocketException: Connection reset

我是配置了2.40的環境在path中,但還是有這個問題。只能在代碼中指定驅動器的路徑,將下列代碼加在實例化驅動之前即可。

System.setProperty("webdriver.chrome.driver", "C:\\Users\\anyan\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe");

以下提供我的測試代碼實例:

import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumBuildExample {
    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\anyan\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe");
        WebDriver webDriver=new ChromeDriver();

        webDriver.navigate().to("http://www.baidu.com");
        WebElement search_input=webDriver.findElement(By.name("wd"));
        search_input.sendKeys(時間");
        search_input.submit();
        Thread.sleep(3000);
        Assert.assertEquals("時間_百度搜索",webDriver.getTitle());
        webDriver.quit();
    }
}

 

 

 

 

驅動下載地址:http://chromedriver.storage.googleapis.com/index.html

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