java 版 selenium 自動化操作 chrome

 一、selenium 在java中的使用

System.setProperty("webdriver.chrome.driver", local);//加載chrome 位置
        ChromeOptions options = new ChromeOptions();
        options.addArguments("window-size=1280,728");   //設置窗口大小
//        String user_data = System.getProperty("user.dir") + "\\src\\com\\selenium\\chrome_data";
//        options.addArguments("user-data-dir=" + user_data); 
//        options.addArguments("headless=true"); //無頭
        DesiredCapabilities cap = DesiredCapabilities.chrome();
        cap.setCapability(ChromeOptions.CAPABILITY, options);
        cap.setCapability("goog:" + ChromeOptions.CAPABILITY, options);
        WebDriver webDriver = new ChromeDriver(cap);
        RemoteWebDriver  rdriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);//遠程方式,想用多線程需要這麼寫
        rdriver.get("http://pan.baidu.com");

 

 

 

 

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