繁体   English   中英

Selenium:FirefoxProfile 异常无法加载配置文件

[英]Selenium: FirefoxProfile exception Can't load the profile

根据上一个问题,我将 Selenium 更新到版本 2.0.1 但现在我遇到了另一个错误,即使配置文件存在于/tmp/webdriver-py-profilecopy

  File "/home/sultan/Repository/Django/monitor/app/request.py", line 236, in perform
    browser = Firefox(profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 46, in __init__
    self.binary, timeout),
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 46, in __init__
    self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 44, in launch_browser
    self._wait_until_connectable() 
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 87, in _wait_until_connectable
    raise WebDriverException("Can't load the profile. Profile Dir : %s" % self.profile.path)
selenium.common.exceptions.WebDriverException: Can't load the profile. Profile Dir : /tmp/webdriver-py-profilecopy

怎么了? 我该如何解决这个问题?

更新:

Selenium 团队已在最新版本中修复。 对于几乎所有环境,修复是:

pip 安装-U selenium

不清楚它是在哪个版本修复的(显然是r13122 ),但肯定到 2.26.0(更新时的当前版本)它是固定的。


这个错误意味着_wait_until_connectable正在超时,因为由于某种原因,代码无法连接到已经加载到firefox中的webdriver扩展。

我刚刚向 selenium 报告了一个错误,因为我正在尝试使用代理,并且配置文件中的 4 个已配置更改中只有 2 个已被 firefox 接受,所以我收到此错误,因此代理未配置为与扩展名。 不知道为什么会这样……

https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/2061

将 Ubuntu 升级到 12.04 后,我遇到了同样的问题。

该问题出现在 package 端,并已在最新版本的库中得到修复。 只需更新 selenium 库即可。 对于几乎所有 Python 环境,这是:

pip install -U selenium

我在使用 FF 32.0 和 Selenium selenium-2.42.1-py2.7.egg 时遇到了同样的问题。 尝试更新selenium,但已经是最新版本了。 解决方案是将 Firefox 降级到版本 30。这是过程:

#Download version 30 for Linux (This is the 64 bit)
wget http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/30.0/linux-x86_64/en-US/firefox-30.0.tar.bz2

tar -xjvf firefox-30.0.tar.bz2
#Remove the old version
sudo rm -rf /opt/firefox*
sudo mv firefox /opt/firefox30.0
#Create a permanent link
sudo ln -sf /opt/firefox30.0/firefox /usr/bin/firefox

这解决了所有问题,并且这种组合效果更好!

作为对Jeff Hoye的回答的扩展,更“Pythonic”的方式是webdriver.firefox.firefox_profile.FirefoxProfile如下:

class CygwinFirefoxProfile(FirefoxProfile):
    @property
    def path(self):
        path = self.profile_dir
        # Do stuff to the path as described in Jeff Hoye's answer
        return path

然后,创建您的驱动程序:

driver = webdriver.Firefox(firefox_profile=CygwinFirefoxProfile())

如果pip install -U selenium不起作用(在我的情况下它不起作用),请尝试将 Firefox 降级到以前的版本。

我有 Firefox 49.0 并降级到 45.0 以确保 selenium 支持该版本。 那时它工作得很好。

这是降级到 Firefox 45.0 的快速方法:

sudo apt-get install firefox=45.0.2+build1-0ubuntu1

希望这可以帮助。

如果您从 cygwin 运行 webdriver,问题是配置文件的路径仍然是 POSIX 格式,这会混淆 windows 程序。 我的解决方案使用 cygpath 将其转换为 Windows 格式。

在这个文件/方法中:selenium.webdriver.firefox.firefox_binary.launch_browser():

代替:

    self._start_from_profile_path(self.profile.path)

和:

    from subprocess import Popen, PIPE
    proc = Popen(['cygpath','-d',self.profile.path], stdout=PIPE, stderr=PIPE)
    stdout, stderr = proc.communicate()
    path = stdout.split('\n', 1)[0]

    self._start_from_profile_path(path)
    #self._start_from_profile_path(self.profile.path)

由于 Python 甚至不接近我的主要编程语言,如果有人可以推荐一种更 Python 的方法,也许我们可以将其推送到发行版中。 如果它在 cygwin 中开箱即用,它肯定会很方便。

我遇到了同样的问题,并认为这是 selenium / Firefox 的错误组合。 原来 my.mozilla/ 文件夹权限只能由 root 用户访问。 chmod 770 ~/.mozilla/就行了。 我建议在进一步排除故障之前确保这不是问题。

pip install -U selenium

我在Firefox 34.0.5 (Dec 1, 2014)遇到了同样的问题,将 Selenium 从2.42.1升级到2.44.0解决了我的问题。

然而,我已经再次看到这个问题,我认为是 2.44.0,另一个升级修复了它。 所以我想知道它是否可以通过简单地卸载然后重新安装来解决。 如果是这样,我不确定这表明潜在的问题是什么。

我使用的是 selenium 2.53 和 firefox 版本 55.0。 我通过安装旧版本的 firefox (46.0.1) 解决了这个问题,因为 selenium 2.53 不适用于 firefox 及以上版本 4。

这不是一个合适的解决方案,但对我有用,如果有人可以改进我会很高兴知道。 我只是以 root 身份运行我的脚本: sudo python myscript.py 我想我可以通过更改配置文件默认文件或目录来解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM