Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use chrome extensions in Selenium

I have been looking for an answer to this question for a long time, but I have not found it. I figured out how to install the extension using Selenium, but I still didn't figure out how to interact with it. For example, I install the Metamask extension. How do I open it and use its interface? Is there even such a possibility in Selenium?

So I install the extension

options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_extension("D:\\PyCharmProjects\\chromedriver\\metamask.crx")
driver = webdriver.Chrome(options=options)

I tried to launch the extension using hotkeys, it opened, but I couldn't interact with it.

like image 918
kozlik90 Avatar asked Dec 21 '25 14:12

kozlik90


1 Answers

Yes it possible to open chrome extensions using selenium, you can open Metamask using below code :

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('start-maximized')
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_extension('Metamask.crx')
driver = webdriver.Chrome(options=chrome_options)   
driver.get('chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html')

As you see the link contains extension ID so if you want to use another extension just change the ID & interface html name (probably it named 'index.html','home.html')

like image 174
AbdeLhalimSB Avatar answered Dec 23 '25 03:12

AbdeLhalimSB