我想在VS 2010 C#中使用Selenium Web Driver打开Chrome浏览器,导航到某个网页,然后关闭驱动程序但保持浏览器打开。我意识到之后我将不得不手动关闭浏览器,我很好。
到目前为止,我有:
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]
我已尝试以下所有内容作为最后一行
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
有什么想法吗?
答案 0 :(得分:0)
这根本不可能,那种分离不存在。
答案 1 :(得分:0)
chromeservice.driver.close()
过去对我有用,但在这种情况下,您可能需要为方法编写一些代码。
答案 2 :(得分:0)
我们可以使用“detach”选项从chromedriver分离chrome实例。
示例代码:
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();