在WebDriver中加载Firefox扩展时拒绝权限

时间:2015-07-28 07:10:10

标签: python firefox selenium webdriver

我正在使用selenium webdriver创建一个python脚本。我需要在firefox中使用扩展,但是当我使用一个小脚本进行测试时,该脚本会产生如下错误:

Traceback (most recent call last):
  File "C:\Users\User\Desktop\Bot\Mania.py", line 8, in <module>
    firefoxProfile.add_extension(elem)
  File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 93, in add_extension
    self._install_extension(extension)
  File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 264, in _install_extension
    with open(os.path.join(tmpdir, name), 'wb') as f:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\User\\AppData\\Local\\Temp\\tmpzq3rmztk.firebug-2.0.11-fx.xpi\\content/firebug/'
[Finished in 0.4s with exit code 1]

示例代码是:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os

firefoxProfile = FirefoxProfile()
elem = "quickjava-2.0.6-fx.xpi"
firefoxProfile.add_extension(elem)
firefoxProfile.set_preference("thatoneguydotnet.QuickJava.startupStatus.CSS", 2)
driver = webdriver.Firefox(firefoxProfile)
driver.get('http://www.google.cl')

PS:该加载项与脚本位于同一文件夹中。我用完整的路径进行了测试,但它也没有用。

1 个答案:

答案 0 :(得分:2)

您需要提供扩展程序的绝对路径:

firefoxProfile.add_extension("/absolute/path/to/the/extension")