I am new to selenium webdriver and by default when i run a script it is opening a session in Firefox. now i want to open this session in other browsers like Google Chrome, IE.

How can i open this sessions?

Thanks Kamlesh

4 Answers 4


To create an instance of a browser when running WebDriver test you need to create a driver specific to that browser. Firefox works by default, but to work with other browsers such as chrome you may have to download the driver separately.

This website will give you information on how to install the chrome driver and how to get it running.

You will need to have chrome installed on your test machine as well. Other drivers for other browsers can be installed in the same manner.

You can download them from the links given below,

    package mercuryreg;
    import java.util.regex.Pattern;
    import java.util.concurrent.TimeUnit;
    import org.junit.*;
    import static org.junit.Assert.*;
    import static org.hamcrest.CoreMatchers.*;  
    import org.openqa.selenium.*;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.Select;
    import com.thoughtworks.selenium.webdriven.commands.IsElementPresent;

    public class MercuryReg {

      public void mMercuryReg() throws Exception {

          System.setProperty("webdriver.chrome.driver", "E:\\Softwares_Must_Have\\sele\\chromedriver\\chromedriver.exe");

            WebDriver driver = new ChromeDriver(); 

            //Open Home Page
            //Enter text in search box
            WebElement fname=driver.findElement(By.name("firstName"));

  • It would help if you explained what your code is doing to open the session in different browsers instead of just pasting code. That will make your answer useful to anyone looking for this information.
    – Kate Paulk
    Commented Jul 15, 2014 at 10:59
System.setProperty("webdriver.chrome.driver", "E:\\Softwares_Must_Have\\sele\\chromedriver\\chromedriver.exe");
     WebDriver driver = new ChromeDriver(); 

this is the syntax to locate the third party driver,. you have to download the driver. then you have to initiate and call it..

thanks Prakash and am new to stackexchange..


This is possible using the cookies concept of selenium webdriver.

Please refer the below code

public class SessionRestoring {
public WebDriver driver;

    public void test() throws InterruptedException{
        driver=new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        //I took gmail.com to show session management
        //First login to gmail using the firefox driver
        driver.findElement(By.id("Email")).sendKeys("email id here");
        driver.findElement(By.id("Passwd")).sendKeys("mail password here");
        //After login store all cookies into Set<Cookie> type reference variable
        Set<Cookie> allCookies=driver.manage().getCookies();
        //Quit the driver
        //setProperty to the system to open Chrome Driver
        driver=new ChromeDriver();
        //Get the same webpage in the new driver i.e, ChromeDriver
        //Add all the cookies which you saved previously.
        for(Cookie c:allCookies){
        //Just Refresh the browser using navigate().refresh() method.
        //You are done with restoring the session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.