Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

How to load extension within chrome driver in selenium with python

All my efforts to open chrome browser with Browsec extension enabled are failing. Here is what i tried in last -

# Configure the necessary command-line option.
options = webdriver.ChromeOptions()
options.add_argument(r'--load- 
extension=C:Userslap0042AppDataLocalGoogleChromeUser 
DataDefaultExtensionsomghfjlpggmjjaagoclmmobgdodcjboh')

# Initalize the driver with the appropriate options.
driver = webdriver.Chrome(chrome_options=options)

driver.get("http://stackoverflow.com")

This results in error "Failed to load extension from . Manifest files is missing or unreadable"

After search for this error I get that Manifest.json file should be renamed to manifest.json.txt but doing this resulted in same error.

Any help will be highly appreciated

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To open chrome browser with any extension you need to use the add_extension() method through an instance of chrome.options class and you can use the following solution :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_extension(r'C:pathoextension.crx')
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()

References

You can find the relevant documentation in:

You can find a couple of relevant discussions in:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...