Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 如何开始使用Chrome驱动程序和所有现有浏览器cookie?_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Selenium 如何开始使用Chrome驱动程序和所有现有浏览器cookie?

Selenium 如何开始使用Chrome驱动程序和所有现有浏览器cookie?,selenium,selenium-webdriver,selenium-chromedriver,Selenium,Selenium Webdriver,Selenium Chromedriver,据我目前所知,Chrome驱动程序启动时总是没有任何存储的浏览器cookie 我需要驱动程序从Chrome存储的所有cookie开始 我想知道是否有任何方法可以用已经存储的cookies启动驱动程序?我正在使用C#with.NET4.5。是的,我们可以通过调用保存的chrome配置文件来实现,就像firefox配置文件一样。下面是我以前做这件事时注意到的步骤 在Java中,我们可以通过使用ChromeOptions和ChromeProfile来实现这一点。在chrome中导航到chrome://

据我目前所知,Chrome驱动程序启动时总是没有任何存储的浏览器cookie

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


我想知道是否有任何方法可以用已经存储的cookies启动驱动程序?我正在使用C#with.NET4.5。

是的,我们可以通过调用保存的chrome配置文件来实现,就像firefox配置文件一样。下面是我以前做这件事时注意到的步骤

在Java中,我们可以通过使用ChromeOptions和ChromeProfile来实现这一点。在chrome中导航到chrome://version/ 它将显示配置文件路径和可执行文件路径

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

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://stackoverflow.com/");
Map prefs=new HashMap();
prefs.put(“二进制”,“C:\\ProgramFiles(x86)\\Google\\Chrome\\Application\\Chrome.exe”);
System.setProperty(“webdriver.chrome.driver”,“E:\\selenium\u setups\\poi-3.12\\chromedriver.exe”);
ChromeOptions选项=新的ChromeOptions();
选项。设置实验选项(“prefs”,prefs);
options.addArguments(“用户数据目录=C:\\Users\\murali\\AppData\\Local\\Google\\Chrome\\user data\\Profile 3”);
DesiredCapabilities=DesiredCapabilities.chrome();
能力。设置能力(ChromeOptions.CAPABILITY,选项);
WebDriver=新的ChromeDriver(功能);
//WebDriver=新的ChromeDriver(选项);
驱动程序。获取(“http://stackoverflow.com/");
据我所知,我不希望stackoverflow.com页面显示为已登录。但这是我第一次没有登录。因此,与chrome://version/ 在由驱动程序打开的chrome中,配置文件路径显示为 \Local\Google\Chrome\User Data\Profile 3\Default。然后手动登录到该配置文件,由webdriver打开并通过关闭该配置文件来执行


最后,页面显示为已登录。所以它可能是在java中,我希望它能帮助您尝试使用C语言。

我不确定您的假设是否正确。每当我启动selenium webdriver会话时,我的登录会话仍然存在。因此,饼干应该在那里。