我正在使用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:附件与脚本位于同一文件夹中。我测试了完整的路径,但它也不起作用。

最佳答案

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

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

10-04 10:45