Reusing Existing Browser Session in Selenium

During script development or debugging in selenium, if we can attach the code to an existing browser session, it will make things easier. Here is how to do it with Chrome.

  • Open chrome with remote debugging port
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
  • Start chrome driver
    WebDriver wdriver =null;
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222"); 

    driver = new ChromeDriver(options);