使用 Selenium 扩展 (Python) [英] Using Extensions with Selenium (Python)
本文介绍了使用 Selenium 扩展 (Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用 Selenium 运行 Chrome 实例来测试网页.每次我的脚本运行时,都会启动一个干净的 Chrome 实例(清除扩展程序、书签、浏览历史记录等).我想知道是否可以使用 Chrome 扩展程序运行我的脚本.我试过搜索 Python 示例,但在 google 上搜索时没有任何结果.
I am currently using Selenium to run instances of Chrome to test web pages. Each time my script runs, a clean instance of Chrome starts up (clean of extensions, bookmarks, browsing history, etc). I was wondering if it's possible to run my script with Chrome extensions. I've tried searching for a Python example, but nothing came up when I googled this.
推荐答案
你应该使用 Chrome WebDriver options 设置要加载的扩展列表.举个例子:
You should use Chrome WebDriver options to set a list of extensions to load. Here's an example:
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
executable_path = "path_to_webdriver"
os.environ["webdriver.chrome.driver"] = executable_path
chrome_options = Options()
chrome_options.add_extension('path_to_extension')
driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
driver.get("http://stackoverflow.com")
driver.quit()
希望有所帮助.
这篇关于使用 Selenium 扩展 (Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文