如何使用Chrome访问我现有的Cookie? [英] How do I access my existing cookies using Chrome?

查看:1419
本文介绍了如何使用Chrome访问我现有的Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用Gmail登录信息的Cookie,因此Chrome会自动打开我的Gmail。



我尝试了以下代码,但无法正常工作:

  System.setProperty(webdriver.chrome.driver,chromedriver\\ chromedriver.exe); 
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(chrome.switches,Arrays.asList(C:\\Users\\Owner\\AppData\\Local\\Google\\ Chrome\\User Data\\Default));
//我也试过使用:capabilities.setCapability(chrome.switches,Arrays.asList( - user-data-dir = C:\\Users\\Owner\\ AppData\\Local\\Google\\Chrome\\UserData\\Default));

WebDriver driver = new ChromeDriver(capabilities);

driver.get(https://gmail.com);

我检查了 C:\\Users\\\ \\ Owner\\AppData\\Local\\Google\\Chrome\\UserData\\Default 没关系。
这里有什么问题?

解决方案

有一个已知问题部分我之前没有注意到的Chrome驱动程序官方wiki页面:


已知问题



3。无法指定自定义个人资料


现在,我不知道这是否已过时。我找不到这个bug的报告。这是真的,你不能通过能力(截至2013年7月)指定自定义配置文件,因为你发现。但有一个解决方案...




$ b

解决方案

>以下是我设法使其运行的方法:

  ChromeOptions opt = new ChromeOptions 
opt.setBinary(E:\\some\\path\\chrome.exe);
opt.addArguments( - user-data-dir = C:\\Users\\Owner\\AppData\\Local\\Google\\Chrome\\ \\\用户数据);
driver = new ChromeDriver(opt);

注意用户数据目录的路径 - \\Default 部分。在这种情况下,它对我来说很好,打开存储了所有cookie和登录的Chrome配置文件。



我不知道为什么能力解决方案不工作。 提交错误可能是值得的,因为我找不到主题。


I have cookies with Gmail login info, so that chrome automatically opens my Gmail.

I tried the following code, but it didn't work:

    System.setProperty("webdriver.chrome.driver","chromedriver\\chromedriver.exe"); 
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            capabilities.setCapability("chrome.switches", Arrays.asList("C:\\Users\\Owner\\AppData\\Local\\Google\\Chrome\\User Data\\Default"));
//I also tried using: capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir = C:\\Users\\Owner\\AppData\\Local\\Google\\Chrome\\User Data\\Default"));

            WebDriver driver = new ChromeDriver(capabilities);

            driver.get("https://gmail.com");

I checked the directory of C:\\Users\\Owner\\AppData\\Local\\Google\\Chrome\\User Data\\Default it is okay. What is the problem in here?

解决方案

There is a Known issues section on the Chrome Driver official wiki page I haven't noticed before:

Known Issues

3 . Cannot specify a custom profile

Now, I don't know whether this is or isn't outdated. I could not find a bug report for this. It's true that you can't specify a custom profile via Capabilities (as of July 2013), as you discovered. But there is a solution...


The Solution

Here's how I managed to make it run:

ChromeOptions opt = new ChromeOptions();
opt.setBinary("E:\\some\\path\\chrome.exe");
opt.addArguments("--user-data-dir=C:\\Users\\Owner\\AppData\\Local\\Google\\Chrome\\User Data");
driver = new ChromeDriver(opt);

Notice the path to the User data directory - it does not have the \\Default part. And in that case, it works just fine for me, opens up the Chrome profile stored with all the cookies and logins.

I have no idea why the Capabilities solution does not work. It might be worthwile to file a bug as I could not find one on topic.

这篇关于如何使用Chrome访问我现有的Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆