您如何使用 Chrome 驱动程序和所有现有的浏览器 cookie 启动 selenium?

How do you start selenium using Chrome driver and all existing browser cookies?

据我目前的了解,Chrome 驱动程序总是在没有任何存储的浏览器 cookie 的情况下启动。

我需要驱动程序从 Chrome 存储的所有 cookie 开始。

请问有什么方法可以使用已经存储的cookie启动驱动程序吗?我在 .net 4.5 中使用 C#。

是的,我们可以通过调用保存的 chrome 配置文件来实现,就像 firefox 配置文件一样。以下是我之前做的时候记下的步骤

在 Java 中,我们可以通过使用 Chrome 选项和 Chrome 配置文件来完成。在 chrome 导航到 chrome://version/ 它将显示配置文件路径和可执行文件路径。

根据我的工作,配置文件路径是 \Local\Google\Chrome\User Data\Profile 3 这显示了当我在普通 chrome 浏览器中导航到 chrome://version/ 时显示的内容。在此配置文件中,我导航到 Whosebug 并保存了凭据。所以使用下面的代码

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("binary", "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");

System.setProperty("webdriver.chrome.driver", "E:\selenium_setups\poi-3.12\chromedriver.exe");
ChromeOptions options = new ChromeOptions();

options.setExperimentalOption("prefs", prefs);
options.addArguments("user-data-dir=C:\Users\murali\AppData\Local\Google\Chrome\User Data\Profile 3");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);

//WebDriver driver = new ChromeDriver(options);
driver.get("http://whosebug.com/");

据我了解,我排除了显示为已登录的 whosebug.com 页面。但是我第一次没有登录。所以在 chrome://version/ 中交叉检查 chrome驱动打开,配置文件路径显示为 \Local\Google\Chrome\User Data\Profile 3\Default 。然后手动登录到它自己的配置文件中,它由 webdriver 打开并通过关闭它来执行增益。

最后页面显示为已登录。所以可能在java,希望对你在C#中尝试有所帮助。