所以我在Ubuntu机器上使用IntelliJ IDEA + chromedriver运行了一个selenium测试…
在我的Google Chrome安装中,我已经登录到一个帐户,比如Google。当我在selenium测试中访问http://accounts.google.com时,我会进入登录页面,而不是实际的帐户管理页面。
我很确定我并不完全理解Selenium和chrome驱动程序的具体操作方式,但我记得'Google Chrome安装在默认位置‘是使用chrome驱动程序运行Selenium测试的要求之一。
我是否可以在我安装的浏览器的上下文中运行,即可以访问我的浏览器历史记录和cookies?
发布于 2015-12-10 01:04:11
每次Selenium打开一个浏览器(Chrome/Firefox/IE)时,它都会打开该浏览器的一个规范形式。作为测试人员,您可以使用DesiredCapabilities object设置浏览器首选项,对于chrome,您还可以使用ChromeOptions object传递chrome命令行参数。
选择您的配置文件
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");有关chrome驱动程序功能的更多信息,请访问:https://sites.google.com/a/chromium.org/chromedriver/capabilities
有关chrome的user-data-dir命令行选项的更多信息:
https://www.chromium.org/user-experience/user-data-directory
发布于 2018-06-11 15:45:54
试试这个:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)要找到您的chrome配置文件数据的路径,您需要在地址栏中键入chrome://version/。对于ex。我的显示为C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default,要在脚本中使用它,我必须排除\Default\,所以我们最终只能得到C:\Users\pc\AppData\Local\Google\Chrome\User Data。
来源:How to load default profile in chrome using Python Selenium Webdriver?
https://stackoverflow.com/questions/34179420
复制相似问题