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

sul*_*tan 96 python firefox selenium webdriver selenium-webdriver

根据上一个问题,我将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

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

Rac*_*hel 132

更新:

Selenium团队修复了最新版本.对于几乎所有环境,修复方法是:

pip install -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

  • 不,这个解决方案不适用于Firefox 45.0b和最新的Selenium(2.5.1) (7认同)
  • @AbhranilDas如果你使用`virtualenv`(你可能应该使用),你不需要`sudo`. (5认同)
  • 如果没有以root身份登录,则需要添加`sudo`.无论如何,这是一个救星!谢谢!! (3认同)

小智 31

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

问题出在封装方面,并已在最新版本的库中修复.只需更新selenium库.对于几乎所有Python环境,这是:

pip install -U selenium
Run Code Online (Sandbox Code Playgroud)


Mij*_*ijo 26

我遇到了与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
Run Code Online (Sandbox Code Playgroud)

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


Joe*_*oss 8

作为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
Run Code Online (Sandbox Code Playgroud)

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

driver = webdriver.Firefox(firefox_profile=CygwinFirefoxProfile())
Run Code Online (Sandbox Code Playgroud)


Chr*_*ris 5

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

我使用Firefox 49.0并降级到45.0以确保版本受到selenium的支持.它完美地工作了.

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

sudo apt-get install firefox=45.0.2+build1-0ubuntu1
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.