Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Extensions with Selenium (Python)

Tags:

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.

like image 776
Michael Wu Avatar asked May 12 '13 19:05

Michael Wu


People also ask

Can Selenium use extensions?

We can use extensions with Selenium webdriver in Python. We can have multiple extensions of the Chrome browser while we manually open the browser and work on it. However, while the Chrome browser is opened through Selenium webdriver, those extensions which are available to the local browser will not be present.

How can the add ons be added to Selenium?

Using install_addon API of Selenium WebDriver to add Firefox extensions using Python. The install_addon method of the Selenium WebDriver takes two input arguments – path to the desired Firefox extension and a Boolean value which indicates whether installation of the extension is temporary (or not).


1 Answers

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() 

Hope that helps.

like image 150
alecxe Avatar answered Sep 19 '22 08:09

alecxe