Java實現打開google瀏覽器


說明:

  博主的Google瀏覽器版本:75.0.3770.142,如果運行異常,需要自行查找對應版本的驅動(chromedriver.exe)

 

需要的jar包:

https://pan.baidu.com/s/1KeBhp--zc6BZdoUsrGSkbQ

 

需要的驅動文件(放在Google瀏覽器.exe文件安裝的相同目錄):

https://pan.baidu.com/s/1xtznVCXM4KJmd6Xxms2EXw

 

代碼:

package selenuimTest;

import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

/**
 * 測試----- 通過窗口打開谷歌瀏覽器
 * @author WangSong
 *
 */
public class TestOpenBrowser {

    public static void main(String[] args) {
        //設置啟動google瀏覽器的驅動和位置
        System.setProperty("webdriver.chrome.driver",
                "C:"+File.separator+
                "Program Files (x86)"+File.separator+
                "Google"+File.separator+
                "Chrome"+File.separator+
                "Application"+File.separator+
                "chromedriver.exe");
        System.out.println("啟動 ...");
        //獲取谷歌瀏覽器驅動
        WebDriver driver=new ChromeDriver();
        //設置默認打開的頁面
        driver.get("http://www.baidu.com/");
        //設置默認搜索的關鍵字
        driver.findElement(By.id("kw")).sendKeys("eclipse窗口集成瀏覽器");
        //搜索按鈕點擊
        driver.findElement(By.id("su")).click();
        //關閉瀏覽器
//        driver.close();
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM