Thursday, October 20, 2016

How to open different browsers in Selenium

We will the Java code in which we try to open different browsers.

1. Firefox - For this you need to install forefox browser on your machine. If you are using Selenium version 3.0 or higher than you need to download Gekodriver

public void OpenBrowser()
{
     FirefoxProfile profile = new FirefoxProfile();
     driver = new FirefoxDriver(profile);
     driver.get("http://localhost");
}

2. Chrome and IE browser - You need to download the chromedriver and IEdriver from Selenium website.

public void OpenBrowser()
{
     System.setProperty("webdriver.chrome.driver","Path to chromedriver.exe");
     driver = new ChromeDriver();
    // You can read more about Chrome Profile and capability options over internet.
}

public void OpenBrowser()
{
     System.setProperty("webdriver.ie.driver","Path to IEDriverServer.exe");
     driver = new InternetExplorerDriver();
   
}

For Firefox browser, you need to assure that Selenium and Firefox version should be compatible. You can check the compatibility on internet.


For any queries and suggestions, please mail me at saurabh1484@gmail.com


No comments:

Post a Comment