我可以使用实际Chrome安装的Cookie运行Selenium ChromeDriver吗? [英] Can I run Selenium ChromeDriver with cookies from actual Chrome installation?

查看:1004
本文介绍了我可以使用实际Chrome安装的Cookie运行Selenium ChromeDriver吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在Ubuntu机器上使用IntelliJ IDEA + chromedriver进行硒测试...

So I'm running a selenium test using IntelliJ IDEA + chromedriver on an Ubuntu machine...

在我的Google Chrome安装中,我已登录到谷歌说,帐户。当我在selenium测试中访问 http://accounts.google.com 时,我会转到登录页面实际的帐户管理页面。

In my Google Chrome installation, I have logged in to an account, say Google. When I access http://accounts.google.com in the selenium test, I get to the log in page instead of the actual account management page.

我很确定我不完全了解Selenium和Chrome驱动程序运行的确切方式,但我确实记得将Google Chrome安装在默认位置是使用Chrome驱动程序运行Selenium测试的要求之一。

I'm pretty sure that I don't fully understand the exact way that Selenium and the chrome driver operate, but I do remember that having 'Google Chrome installed in the default location' is one of the requirements of running a Selenium test with the chrome driver.

我是否可以在已安装的浏览器的上下文中运行即可以访问我的浏览器历史记录和cookie?

Can I run in the context of my installed browser i.e. have access to my browser history and cookies?

推荐答案

每次Selenium打开浏览器(Chrome / Firefox / IE)时,它会打开该浏览器的规范形式。作为测试人员,您可以使用DesiredCapabilities对象设置浏览器首选项,对于chrome,您也可以使用ChromeOptions对象来传递chrome命令行参数。

Everytime Selenium opens a browser (Chrome/Firefox/IE) it opens a canonical form of that browser. As a tester, you can set browser preferences using DesiredCapabilities object and for chrome you also can use ChromeOptions object, for passing chrome command line arguments.

选择您的个人资料

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");

有关Chrome驱动程序功能的更多信息:
https://sites.google.com/a/chromium.org/chromedriver/capabilities

For more on chrome driver capabilities: https://sites.google.com/a/chromium.org/chromedriver/capabilities

有关chrome的user-data-dir命令行选项的更多信息:

https://www.chromium.org/user-experience/user-data-directory

For more about user-data-dir command line option for chrome:
https://www.chromium.org/user-experience/user-data-directory

这篇关于我可以使用实际Chrome安装的Cookie运行Selenium ChromeDriver吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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