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

标签 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:该附加组件与脚本位于同一文件夹中。我用完整路径进行了测试,但它也不起作用。

最佳答案

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

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

关于python - 在 WebDriver 中加载 Firefox 扩展时权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31669600/

相关文章:

python - 使用 NLTK 在递归下降解析器中指定重复标记

firefox - 如何为所有属性指定 CSS3 过渡,但有一个异常(exception)/覆盖?

css - Firefox 如何在单元格表格内显示滚动条?

javascript - 从主脚本到内容脚本的多条消息

java - 等待列表中的元素之一

python - 向具有不同行数的 Pandas 数据框添加新列

python - 从父类(super class)实例化子类

python - 在 python 中命名为非捕获组?

java - IndexOutOfBoundException - 从站点检索所有元素

java - 无法使用 Java 使用 Selenium Webdriver 3.0.1 启动 IE8 浏览器