python - Chrome Webdriver 不加载默认配置文件
问题描述
Selenium Chrome Webdriver 不会加载我的默认 Chrome 配置文件。
我已经尝试了许多其他 Stack Overflow 解决方案,包括更改路径(以及使用本地 Chrome 应用程序,它会给出“权限被拒绝”错误)。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=~/Library/Application Support/Google/Chrome/Default")
options.add_argument("--profile-directory=Default")
driver = webdriver.Chrome()
driver.get("https://tagmanager.google.com/#/home")
assert "Google Analytics" in driver.title
account_element = driver.find_element_by_css_selector("div.account.card div#149385038 table")
accountPublicId = driver.find_element_by_css_selector("div#149385038 table td.account__public-id")
结果还是一样;它只加载一个“裸”Chrome Webdriver,而不是加载本地默认配置文件(我每天都在工作中使用)。
更新:
我不知道如何或为什么,但现在,当我退出 Chrome 并通过 Python 脚本启动 Chrome 时,Google Chrome 会从我的个人资料开始,但不使用我在该个人资料中的 cookie。
我将看看是否可以使用options.add_arguments
.
解决方案
尝试这个:
从硒导入网络驱动程序
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\ProfilePath") ##profile path
w = webdriver.Chrome(executable_path="C:\\chromedriver.exe", chrome_options=options)
推荐阅读
- javascript - 如何在fabric js上添加对象到组
- windows - 有没有办法从注册表中找到名称类似于显示名称的 exe 文件
- swift - 添加 UILabel 强制 UICollectionViewCell 缩小宽度
- javascript - 使用 immer.js 更新数组中的一些项目
- html - 为什么尽管http状态为404,图像和图片元素仍显示图像?
- jbpm - 业务流程管理系统抽象
- perl - 如何替换字符串中的非简单变量引用
- ios - addSubview 与呈现模态 ViewController 的区别?
- git - 如何使用 Github Flow 管理版本号?
- java - 解密中的最后一个块不完整 - Android Studio JAVA