我可以使用来自实际 Chrome 安装的 cookie 运行 Selenium ChromeDriver 吗? [英] Can I run Selenium ChromeDriver with cookies from actual Chrome installation?
问题描述
所以我在 Ubuntu 机器上使用 IntelliJ IDEA + chromedriver 运行 selenium 测试......
So I'm running a selenium test using IntelliJ IDEA + chromedriver on an Ubuntu machine...
在我的 Google Chrome 安装中,我登录了一个帐户,比如 Google.当我在 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"是运行 Selenium 的要求之一使用 chrome 驱动程序进行测试.
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屋!