📅  最后修改于: 2023-12-03 15:19:02.616000             🧑  作者: Mango
When using Python with Selenium, there are times when we need to use a Chrome extension to complete some tasks. In this guide, we will go over the steps needed to open a Chrome extension with a Python WebDriver.
Before starting, you should have the following:
webdriver
module to automate the Chrome browser, and the os
module to set the Chrome options.from selenium import webdriver
import os
chrome_options = webdriver.ChromeOptions()
chrome_options.add_extension('/path/to/extension.crx')
Replace /path/to/extension.crx
with the actual path to your Chrome extension.
driver = webdriver.Chrome(options=chrome_options)
This will open a new Chrome window with the extension loaded.
Here is the full example code:
from selenium import webdriver
import os
chrome_options = webdriver.ChromeOptions()
chrome_options.add_extension('/path/to/extension.crx')
driver = webdriver.Chrome(options=chrome_options)
Make sure to replace /path/to/extension.crx
with the actual path to your Chrome extension.
And there you have it! You now know how to open a Chrome extension with a Python WebDriver. This can be useful for automating tasks that require the use of a specific extension.