Python Selenium:FirefoxProfile异常可以';不要加载配置文件

Python Selenium:FirefoxProfile异常可以';不要加载配置文件,python,firefox,selenium,selenium-webdriver,webdriver,Python,Firefox,Selenium,Selenium Webdriver,Webdriver,Per I将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/webd

Per I将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 文件“/home/sultan/Repository/Django/monitor/app/request.py”,执行中第236行 浏览器=Firefox(配置文件) 文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/firefox/webdriver.py”,第46行,在__ self.binary,超时), 文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension\u connection.py”,第46行,在__ self.binary.launch_浏览器(self.profile) 文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/firefox/firefox\u binary.py”,第44行,在启动浏览器中 self.\u等待\u直到\u可连接() 文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/firefox/firefox\u binary.py”,第87行,在“等待”直到“可连接” 引发WebDriverException(“无法加载配置文件。配置文件目录:%s”%self.profile.path) selenium.common.exceptions.WebDriverException:无法加载配置文件。Profile Dir:/tmp/webdriver py profilecopy
怎么了?我如何解决这个问题

更新:

Selenium团队在最新版本中进行了修复。对于几乎所有的环境,解决方案是:

pip安装-U selenium

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


此错误意味着_wait _,直到_connectable超时,因为出于某种原因,代码无法连接到已加载到firefox中的webdriver扩展

我刚刚向selenium报告了一个错误,在那里我得到了这个错误,因为我正在尝试使用代理,并且firefox只接受配置文件中4个配置更改中的2个,因此代理没有配置为与扩展对话。不知道为什么会这样


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

该问题在软件包方面,已在最新版本的库中修复。只需更新selenium库。对于几乎所有Python环境,这是:

pip install -U selenium

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

在此文件/方法中: selenium.webdriver.firefox.firefox\u binary.launch\u browser():

替换:

    self._start_from_profile_path(self.profile.path)
与:


由于Python与我的主要编程语言并不接近,如果有人能推荐一种更具Python风格的方法,也许我们可以将其推广到发行版中。如果它能在cygwin中立即运行的话,肯定会很方便。

作为Jeff Hoye答案的扩展,一种更“Pythonic”的方法是将
webdriver.firefox.firefox\u 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())

我在FF 32.0和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

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

pip安装-U selenium

我在Firefox 34.0.5(2014年12月1日)上也遇到了同样的问题,Selenium从
2.42.1
升级到
2.44.0
解决了我的问题


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

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

我也有同样的问题,我认为这是selenium/Firefox的错误组合。结果表明,my.mozilla/文件夹权限只能由root用户访问。做
chmod770~/.mozilla/
就成功了。我建议在进一步排除故障之前确保这不是问题。

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

我使用了Firefox 49.0,并将其降级为45.0,以确保该版本受selenium支持。当时它工作得很好

以下是一种快速降级到Firefox 45.0的方法:

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

希望这有帮助。

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

如果不以root用户身份登录,则需要添加
sudo
。无论如何,这是一个救命恩人!谢谢是的,它有助于修复WebDriverException:消息:“无法加载配置文件”。@AbhranilDas如果您使用的是
virtualenv
(您可能应该使用)。不,此解决方案不适用于Firefox 45.0b和最新的Selenium(2.5.1)@AlexG.P。4.5年前,我第一次写下了这个问题的答案。我怀疑已经过了足够的时间,可能值得提出一个新问题。如果您这样做,请包括对这个问题的参考:a)您在上面给出的Firefox和Selenium版本;b) 你的操作系统;c) 你的pip版本。我猜你的问题可能与pip版本有关,因为在过去的5年里,pip版本已经发生了变化。不知道为什么,但是在使用selenium 2.28.0的同时,我对Ubuntu上的FireFox 22.0和23.0也有同样的问题。只有将firefox降级到18.0对我来说很好(从未检查过其他版本)。我在Windows中遇到与2.44和ff35完全相同的问题。这修复了我的设置!!如何在mac上降级Firefox?我在“virtualenv”上的mactop上使用scrapy/selenium,并且
sudo apt-get install firefox=45.0.2+build1-0ubuntu1