【问题标题】:Chromedriver do not open a new session, it opens a new tab in a existing sessionChromedriver 不打开新会话,它会在现有会话中打开一个新选项卡
【发布时间】:2021-04-01 07:06:23
【问题描述】:

我的代码在某些 PC 上运行正常,但有一个代码不会打开新的私人会话,在这种特殊情况下,它会在已打开的同一窗口中加载当前的 chrome 配置文件。 我尝试查看一些 stackoverflow 问题,看看是否发生在其他人身上,但没有成功。尝试查看此命令行列表“https://peter.sh/experiments/chromium-command-line-switches/”以查看是否有帮助,但我不知道如何使其工作。 即使没有打开会话,它也会加载默认用户配置文件并且没有任何反应。 Selenium、chrome 和 chromedriver 是最新的并具有匹配的版本。

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.common.exceptions import NoSuchElementException as NSEE

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--start-maximized')

browser = webdriver.Chrome(options=chrome_options)

【问题讨论】:

  • 禁用杀毒软件。
  • 我想到了,但您可以想象一种无需外部人为干预即可运行代码的方式吗?
  • 感谢您的回答。我试过了,但没有用。
  • 您可以将该机器上使用的配置文件添加到问题中吗?应该在~/.config/google-chrome/ 还有,从命令行运行 chrome 会发生什么?
  • 对不起@JamesBurgess,我刚刚将浏览器更改为firefox以避免错误,它工作正常,我也无法获取配置文件。感谢您的帮助。

标签: python python-3.x selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

您可以在实例化 webdriver 之前将隐身标志显式传递给 chrome。

 chrome_options.add_argument('-incognito')

我怀疑这只发生在已经在 chrome 上登录的机器上。

【讨论】:

  • 实际上是另一台机器登录了,但没有发生。我在另外 3 台机器上试过,只有一台出现了这个问题。
  • 此讨论here 解释了 chrome 登录行为的工作原理。 (除非传入--profile-directory=<user> 标志,否则始终以最后一个用户身份登录。)
  • 让 e 毛骨悚然的是,它以前在任何其他机器上都没有发生过,即使在这个特定问题发生之前,即使在登录 chrome 中它也能正常工作。
  • 感谢您的回答。我试过了,但也没有用。
猜你喜欢
  • 2017-05-26
  • 1970-01-01
  • 2017-07-07
  • 1970-01-01
  • 2012-09-01
  • 2021-06-09
  • 2018-06-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多