1、chrome,chromedriver.exe试了很多次,把chrome浏览器添加到环境变量path下最后放到chrome.exe同一路经下才能用,不知道是不是因为安装在D盘的原因
String driverPath = "D:\\Program Files\\Chrome\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", driverPath);driver = new ChromeDriver();
driver.get("http://www.baidu.com");
2、火狐,火狐浏览器需要确保添加到环境变量path里
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "D:\\Program Files\\Mozilla Firefox\\firefox.exe”);
driver = new FirefoxDriver(profile);
driver.get("http://www.baidu.com");
3、IE,
System.setProperty("webdriver.ie.driver", "F:\\IEDriverServer.exe");
InternetExplorerDriverService service = (new org.openqa.selenium.ie.InternetExplorerDriverService.Builder()).usingAnyFreePort().build();
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability("ignoreProtectedModeSettings", true);
capabilities.setCapability("unexpectedAlertBehaviour", "accept");
driver = new InternetExplorerDriver(service, capabilities);