I've upgraded to selenium 4
new_addon_path = 'D:/GOOD/Coding/uBlock.xpi'
browser1 = selenium.webdriver.Firefox(options=opts, etc....)
browser1.install_addon(new_addon_path)
Error:
selenium.common.exceptions.WebDriverException: Message: Expected absolute path: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) .....
Documentation:
https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/CHANGES.md
The documentation says:
Changes to firefox.Driver .. Added installAddon(path)
A temporary profile automatically is created in C:/Users/User/AppData/Local/Temp/
I want this temporary profile, so that I can thread multiple driver sessions at once without creating and assigning new profiles manually.
This temp profile can be found using browser1.__dict__['capabilities']['moz:profile']
Fixes I have tried:
tried placing uBlock.xpi
into profile folder, then calling browser1.install_addon(path to profile/extensions/uBlock.xpi)
tried placing uBlock.xpi
in same folder as geckodriver.log
All paths fail, regardless of if they are relative or apsolute paths.
Documentation also says:
Changes to firefox.Options .. Added addExtensions
which does not even exist as an option in firefox.Options
The lads at github.com solved the issue,
browser1.install_addon('D:/GOOD/Coding/uBlock.xpi')
should look like:
browser1.install_addon(r'D:\GOOD\Coding\uBlock.xpi')
This works
I'm not sure why, since the service()
function or any other python selenium functions works perfectly fine on windows with blackslashes. This path however requires this formula.