Run Selenium Java Scripts in already Opened Browser

This demo will be using chrome browser to run selenium scripts.

Adding Chrome to Environment Variable

  • Click start and type Environment Variable. Select “Edit environment variable for your account”.
  • Select Path and click edit.
  • Add the path where your chrome.exe is present. Usually it will be present in “C:\Program Files (x86)\Google\Application”.
  • Test addition of chrome path using command prompt. Execute the below command, it should open your chrome browser.
  • Type following command to open chrome on remote debugging mode. Change to any port which is available.
chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\Selenium\ChromeProfile"
  • This will create a folder “Selenium” in C drive to keep all data related to chrome.
  • Open your Selenium Java code and add the following code to create chrome driver to point to chrome running in debugger mode at port 9222.
System.setProperty("", "<Path of Chrome driver>\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
ChromeDriver driver = new ChromeDriver(options);
  • Now all your scripts will be running in already opened chrome browser.

Thank you All!!! Hope you find this useful.

Up ↑

%d bloggers like this: