Open Firefox Webdriver with Adblock Plus Extension (Python)
I want to open Firefox using Python Webdriver and Adblock Plus extension.
Here's my code:
from selenium import webdriver ffprofile = webdriver.FirefoxProfile() ffprofile.add_extension(extension='adblock.xpi') driver = webdriver.Firefox(firefox_profile=ffprofile)
I am getting the following error:
Traceback (last call last): File "adblock_test.py", line 6, in ffprofile.add_extension (extension = 'adblock.xpi') File "C: \ Python34 \ lib \ site-packages \ selenium \ webdriver \ firefox \ firefox_profile .py ", line 92, in add_extension self._install_extension (continued) File" C: \ Python34 \ lib \ site-packages \ selenium \ webdriver \ firefox \ firefox_profile.py ", line 269, in _install_extension addon_details = self._addon_details ( addon) File "C: \ Python34 \ lib \ site-packages \ selenium \ webdriver \ firefox \ firefox_profile.py", line 341, in _addon_details manifest = f.read () File "C: \ Python34 \ lib \ encodings \ cp1252 .py ", line 23, in decoding return codecs.charmap_decode (input, self.errors, decoding_table)  UnicodeDecodeError: codec 'charmap'cannot decode byte 0x8d at position 964: char map character to undefined
Other extensions work with this code without problems. Only the Adblock Plus extension ( https://addons.mozilla.org/de/firefox/addon/adblock-plus/ ) doesn't work. Does anyone know a solution to this problem?
source to share
This is because the adblock plus manifest file contains some Unicode characters.
There are two possible solutions:
Change code in selenium / webdriver / firefox / firefox_profile.py
with open(os.path.join(addon_path, 'install.rdf'), 'r') as f:
with open(os.path.join(addon_path, 'install.rdf'), 'r', encoding='utf8') as f:
- Download adblock_plus.xpi and remove the localization strings from the manifest (you can open the .xpi with any archive manager).
Also, this is a problem you can submit a ticket to the selenium bug tracker, so it is allowed in the selenium itself.
source to share