1、啟動(dòng)firefox瀏覽器
a.如果你的本地firefox是默認(rèn)路徑安裝的話,如下方式即可啟動(dòng)瀏覽器
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com");
b.如果不是默認(rèn)路徑安裝,需要先將firefox.exe配置到系統(tǒng)變量中去,如下:
System.setProperty("webdriver.firefox.bin", "D:\ruanjian\Firefox\azml\firefox.exe");
driver = new FirefoxDriver();
String url = "http://www.baidu.com";
driver.get(url);
2、啟動(dòng)ie瀏覽器,由于ie,chrome瀏覽器的driverServer是由他們自己管理的,我們需要下載相應(yīng)的驅(qū)動(dòng),注意區(qū)分 32位和64位,使用方法如下:
System.setProperty("webdriver.ie.driver", "src\main\resources\IEDriver.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.baidu.com");
同樣,如果ie不是默認(rèn)路徑安裝需要配置bin路徑到系統(tǒng)屬性中去
Tip:加載IEDriverServer的時(shí)候,通常會(huì)因?yàn)榧嫒菽J降脑O(shè)置問(wèn)題,而無(wú)法啟動(dòng),嘗試在創(chuàng)建IEDriver對(duì)象的時(shí)候 加入合適的參數(shù)設(shè)置:
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
3、啟動(dòng)chrome瀏覽器,需要下載chromedriver驅(qū)動(dòng)
System.setProperty("webdriver.chrome.driver","C:\Program Files (x86)\Google\Chrome\Application\chromedriver_x64.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.baidu.com");
4、啟動(dòng)瀏覽器的過(guò)程中,經(jīng)常出現(xiàn)啟動(dòng)瀏覽器窗口,卻沒(méi)有完成輸入url地址的情況,大部分由于版本不兼容造成的。
比如:火狐的會(huì)報(bào)如下錯(cuò)誤
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.