[英]Selenium (C#) Chrome driver: the pages loading is not managed as before since the version 77 of the Chrome web driver
[英]How to Detach Chrome Browser from Chrome Driver (Selenium Web Driver C#)
I want to use Selenium Web Driver in VS 2010 C# to open a Chrome browser, navigate to some web page and then close the driver but keep the browser open . 我意识到之后我将不得不手动关闭浏览器,我可以接受。
到目前为止,我有:
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
有任何想法吗?
我们可以使用“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();
这根本不可能,不存在那种分离。
chromeservice.driver.close()
过去曾为我工作,但在这种情况下,您可能需要为方法编写一些代码。
至少在 c# 中你需要下一行:
driverOptions.AddExcludedArgument("enable-automation");
driverOptions.AddAdditionalCapability("useAutomationExtension", false);
(Python) 当我调用 selenium.get() function 时,Chrome 会在不久之后打开和关闭。 我在网上找到了使用以下代码解决此问题的建议:它在 Python3 中对我有用; MacOSX 12.3 蒙特雷; Chrome 版本 105.0.5195.102
从 selenium 导入 webdriver
选项 = webdriver.ChromeOptions()
options.add_experimental_option("分离", True)
driver = webdriver.Chrome(chrome_options=options, executable_path='/Users/<user_acct_name>/.wdm/drivers/chromedriver/mac64/105.0.5195/chromedriver')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.