Open browser using selenium web driver Chrome, FireFox, IE
The very first step is to open a browser to start the automation of any web application. Selenium provides support for multiple browsers like Chrome, Firefox, and IE. In this tutorial, we are going to discuss how to open a browser using selenium web driver in Java. We will see step by step with chrome browser, Firefox browser, and IE browser.
Open Chrome browser using selenium web driver
Download ChromeDriver.exe.
It will start a server at your machine to perform all the test communication. Download the chrome driver Link “http://chromedriver.storage.googleapis.com/index.html?path=2.20/”; There is multiple option to download Chrome Driver Be careful download according to Operating System.
Create an object of ChromeDriver
WebDriver driver = new ChromeDriver();
Set the system property
System.setProperty("webdriver.chrome.driver", “c:\\lib\\chromedriver.exe”);
There are two parameters in setProperty. In 1st Parameter enters the name of the driver like “webdriver.chrome.driver” and In 2nd you just need to enter the path of ChromeDriver.exe file that you just download I mention above.
Example to Open chrome browser using selenium
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; publicclass Main { publicstaticvoid main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\Automation\\selenium\\lib_files\\chromedriver_win32\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://codebun.com/"); driver.close(); } }
Open Firefox browser using selenium web driver
Download geckodriver.exe.
Download the Gecko driver for Firefox Link “https://github.com/mozilla/geckodriver/releases/tag/v0.9.0”;
There is multiple option to download gecko driver Be careful download according to Operating System.
Create an object of Firefox Driver
WebDriver driver = new FirefoxDriver();
Set the system property
System.setProperty("webdriver.gecko.driver ", “D:\\Automation\\selenium\\lib_files\\firefox\\geckodriver.exe”);
There are two parameters in setProperty. In 1st Parameter enters the name of the driver like “webdriver.gecko.driver” and In 2nd you just need to enter the path of the geckodriver.exe file that you just download I mention above.
Example to Open Firefox browser using selenium
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; publicclass Main { publicstaticvoid main(String[] args) { System.setProperty("webdriver.gecko.driver", "D:\\Automation\\selenium\\lib_files\\firefox\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); driver.get("http://codebun.com/"); driver.close(); } }
Open IE browser using selenium web driver
Download IEDriverServer.exe
Download the chrome driver Link http://selenium-release.storage.googleapis.com/index.html
Create an object of Internet Explorer Driver
InternetExplorerDriverdriver = newInternetExplorerDriver();
Set the system property
There is Two parameter in setProperty. In 1st Parameter enters the name of the driver like “webdriver.ie.driver” and In 2nd you just need to enter the path of IEDriverServer.exe file that you just download I mention above.
System.setProperty("webdriver.ie.driver", “D:\\Automation\\selenium\\lib_files\\Ie\\IEDriverServer.exe”);
Example to Open IE browser using selenium
importorg.openqa.selenium.By; import org.openqa.selenium.ie.InternetExplorerDriver; publicclass Main { publicstaticvoid main(String[] args) { String service = "D:\\Automation\\selenium\\lib_files\\Ie\\IEDriverServer.exe"; System.setProperty("webdriver.ie.driver", service); InternetExplorerDriver driver = new InternetExplorerDriver(); driver.get("http://codebun.com"); } }