python - Chrome 配置文件未加载 Selenium

标签 python selenium

这是我的代码:

from selenium import webdriver

options = webdriver.ChromeOptions() 
options.add_argument(r"user-data-dir=C:\Users\shahr\AppData\Local\Google\Chrome\User Data\Profile 1") #Path to your chrome profile
w = webdriver.Chrome(executable_path=r"C:\Program Files (x86)\chromedriver.exe", options=options)

我从其他 StackOverFlow 答案中尝试了此操作,但它拒绝打开所需的配置文件

最佳答案

chrom_options.add_argument("user-data-dir=C:\\Users\robert.car\\AppData\\Local\\Google\\Chrome\\User Data")

chrom_options.add_argument("profile-directory=Profile 1")

user-data-dir 将配置文件视为默认值,您不必指定它。如果是其他内容,请通过配置文件目录参数指定它

创建配置文件的步骤:

打开:地址栏中的 chrome://version

enter image description here

复制用户目录文件夹完全到例如c:\tmp\newdir

打开复制的用户数据 (newdir) 并搜索名为 Default 的文件夹。这是配置文件文件夹。

重命名默认文件夹为“配置文件 1”

现在使用这个:

chrom_options.add_argument("user-data-dir=c:\\tmp\\newdir")

chrom_options.add_argument("profile-directory=Profile 1")

关于python - Chrome 配置文件未加载 Selenium ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65138426/

相关文章:

Python to excel、openpyxl 和文件格式无效

python - 打印列表中除 Python 中的一个之外的所有字符串元素

python-3.x - 忽略或解决机器人框架中测试自动化的证书警告

node.js - Selenium Webdriver 需要重新启动才能持续运行

python - Selenium:WAITING空元素(跨度)包含任何文本

python - 从列表中获取特定值的范围

python - MainWindow 初始化后关闭

python - 将属性添加到 Django 模型元类中

javascript - Java Selenium - JavaScriptExecutor - 参数属于非法类型 : driverFactory. CustomWebElement

java - 或 selenium xpath 中的条件