添加带有选项headless selenium python的扩展



嗨,我想在selenium上添加扩展i don't care about cookies,但我遇到了以下错误:selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://fihnjjcciajhdojfnbdddfaoknhalnja/_generated_background_page.html

有人能帮我吗?感谢

self.service = Service(self.path)
self.chrome_options = webdriver.ChromeOptions()
self.chrome_options.add_extension("tools/I-don-t-care-about-cookies.crx")
self.chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
self.chrome_options.add_argument('--headless')
self.chrome_options.add_argument('--disable-gpu')
self.chrome_options.add_argument('--no-sandbox')
self.driver = webdriver.Chrome(service=self.service,options=self.chrome_options)```

首先,在Chrome浏览器中安装扩展,并检查它是否有效。然后检查正确的扩展位置。然后你可以在启动chromedriver时安装它,如下所示:

chrome_options = Options()
[...]
chrome_options.add_argument('--load-extension=/home/user/.config/chromium/Default/Extensions/cjpalhdlnbpafiamejdnhcphjbkeiagm/1.43.0_0')

Selenium文档可在https://www.selenium.dev/documentation/

相关内容

  • 没有找到相关文章

最新更新