本文主要是針對Chrome 62 , firefox57 ,和IE11 三個版本的操做。相關的driver 。可點擊如下連接。全部的driver 建議放在瀏覽器的目錄下,本文中全部的driver都放置在對應的瀏覽器根目錄下。java
https://files.cnblogs.com/files/linxinmeng/IE11_win10_3.5.zipweb
https://files.cnblogs.com/files/linxinmeng/Firefox57_win10_java1.8.zipchrome
https://files.cnblogs.com/files/linxinmeng/chromedriver_X64_Chrome62.zip瀏覽器
IE瀏覽器須要對安全進行設置 。以及【設置】中的縮放必須是100%。安全
1 package 票務系統前臺; 2 3 import java.util.concurrent.TimeUnit; 4 5 import org.openqa.selenium.WebDriver; 6 import org.openqa.selenium.chrome.ChromeDriver; 7 import org.openqa.selenium.chrome.ChromeOptions; 8 import org.openqa.selenium.firefox.FirefoxDriver; 9 import org.openqa.selenium.firefox.FirefoxOptions; 10 import org.openqa.selenium.firefox.FirefoxProfile; 11 import org.openqa.selenium.firefox.internal.ProfilesIni; 12 import org.openqa.selenium.ie.InternetExplorerDriver; 13 import org.openqa.selenium.remote.DesiredCapabilities; 14 15 public class 瀏覽器操做 { 16 static WebDriver driver; 17 18 public static void main(String[] args) { 19 // IE_open(driver); 20 // firefox_Open1(driver); 21 chrome_Open(driver); 22 24 } 25 26 public static WebDriver chrome_Open(WebDriver driver) { 27 System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver_X64\\chromedriver_X64.exe"); 28 ChromeOptions Options = new ChromeOptions(); 29 Options.addArguments("user-data-dir=C:\\Users\\linxinmeng\\AppData\\Local\\Google\\Chrome\\User Data"); 30 driver = new ChromeDriver(Options); 31 driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS); 32 33 driver.get("http://www.baidu.com"); 34 return driver; 35 } 36 37 public static WebDriver IE_open(WebDriver driver) { 38 System.setProperty("webdriver.ie.driver", "C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer.exe"); 39 driver = new InternetExplorerDriver(); 40 driver.get("http://www.baidu.com"); 41 return driver; 42 43 } 44 45 public static WebDriver firefox_Open1(WebDriver driver) { 46 47 System.setProperty("webdriver.firefox.bin", "D:\\軟件應用寶\\Mozilla Firefox\\firefox.exe"); 48 System.setProperty("webdriver.gecko.driver", "D:\\軟件應用寶\\Mozilla Firefox\\geckodriver.exe"); 49 FirefoxOptions ffo = new FirefoxOptions(); 50 driver = new FirefoxDriver(ffo); 51 driver.get("https://www.baidu.com"); 52 return driver; 53 } 54 55 }