【问题标题】:Chrome Webdriver doesn't load the default profileChrome Webdriver 不加载默认配置文件
【发布时间】:2019-12-01 17:15:35
【问题描述】:

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“手动”添加 cookie。

【问题讨论】:

  • 它在 C# 中,但你读过这个吗? stackoverflow.com/questions/50635087/…
  • 其实应该是用Python写的。那么正确的代码是什么?我确实查看了错误的文章,但我不知道什么是正确的?
  • 你误会了,我不是说你的代码是 C#,而是我链接的另一个问题中的代码。

标签: python macos selenium google-chrome selenium-chromedriver


【解决方案1】:

试试这个:

从硒导入网络驱动程序

options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\ProfilePath") ##profile path
w = webdriver.Chrome(executable_path="C:\\chromedriver.exe", chrome_options=options)

【讨论】:

  • 不幸的是,它也不起作用 - 问题仍然存在。我仍然有一个“裸”的 Chrome 开口。 ?
猜你喜欢
  • 1970-01-01
  • 2015-09-12
  • 1970-01-01
  • 2014-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多