How to separate Chrome browser from Chrome driver (Selenium Web Driver C #)

I want to use the Selenium Web Driver in VS 2010 C # to open a Chrome browser, go to some web page and then close the driver, but don't open the browser . I understand that after that I will have to manually close the browser, and I'm fine with that.

So far I:

DriverService service = ChromeDriverService.CreateDefaultService();
ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("chrome.detach",true);
m_driver = new ChromeDriver(service, options, TimeSpan.FromMilliseconds(1000));
[m_driver does stuff like navigate page, double click stuff, etc]
[last line: try to close driver but not browser]

I tried all of the following as the last line

m_driver.Dispose(); // closes both browser and driver

m_driver.Close(); //closes just the browser and not the driver

m_driver.Quit(); // closes both browser and driver

service.Dispose(); // closes both browser and driver

Any ideas?

+5
source share
3 answers

It is simply impossible; such a separation does not exist.

0
source

chromeservice.driver.close ()

worked for me in the past, but in this case you may need to write some encoding for the method.

0

We can detach the chrome instance from the chrome rib using the "detach" options.

Code example:

ChromeDriverService cdservice = new ChromeDriverService.Builder()
                .usingDriverExecutable(new File("/path/to/chromedriver.exe"))
                .withLogFile(new File("/path/to/chromedriver.log"))
                .usingAnyFreePort().withVerbose(true).build();
cdservice.start();
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("detach", true);
ChromeDriver driver = new ChromeDriver(cdservice,options);
driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
driver.get("http://www.google.com/");

// Do not call driver.quit().. instead stop chromedriver service.
cdservice.stop();
0
source

All Articles