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

发布于 2024-11-19 15:37:18 字数 1175 浏览 2 评论 0原文

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

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

Per this previous question I updated Selenium to version 2.0.1
But now I have another error, even when the profile files exist under /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

What is wrong? How can I resolve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

凤舞天涯 2024-11-26 15:37:19

更新:

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

pip install -U 硒

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


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

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

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

Update:

Selenium team fixed in latest version. For almost all environments the fix is:

pip install -U selenium

Unclear at which version it was fixed (apparently r13122), but certainly by 2.26.0 (current at time of update) it is fixed.


This error means that _wait_until_connectable is timing out, because for some reason, the code cannot connect to the webdriver extension that has been loaded into the firefox.

I have just reported an error to selenium where I am getting this error because I'm trying to use a proxy and only 2 of the 4 configured changes in the profile have been accepted by firefox, so the proxy isn't configured to talk to the extension. Not sure why this is happening...

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

爱人如己 2024-11-26 15:37:19

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

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

pip install -U selenium

I had the same issue after upgrading Ubuntu to 12.04.

The issue was on the package side and has been fixed in the latest version of the library. Just update the selenium library. For almost all Python environments this is:

pip install -U selenium
别在捏我脸啦 2024-11-26 15:37:19

我在 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

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

I faced the same problem with FF 32.0 and Selenium selenium-2.42.1-py2.7.egg. Tried to update selenium, but it is already the latest version.
The solution was to downgrade Firefox to version 30. Here is the process:

#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

This solved all the problems, and this combination works better !

情仇皆在手 2024-11-26 15:37:19

作为 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())

As an extension to Jeff Hoye's answer, a more 'Pythonic' way would be to subclass webdriver.firefox.firefox_profile.FirefoxProfile as follows:

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

Then, to create your driver:

driver = webdriver.Firefox(firefox_profile=CygwinFirefoxProfile())
半衬遮猫 2024-11-26 15:37:19

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

我使用的是 Firefox 49.0,并降级到 45.0 以确保该版本受 selenium 支持。那时它工作得很好。

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

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

希望对您有所帮助。

If pip install -U selenium doesn't work (it didn't, in my case), try downgrading your Firefox to a previous version.

I had Firefox 49.0 and downgraded to 45.0 to make sure the version is supported by selenium. It worked perfectly then.

Here's a fast way to downgrade to Firefox 45.0:

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

Hope this helps.

独留℉清风醉 2024-11-26 15:37:19

如果您从 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 与我的主要编程语言并不接近,如果有人可以推荐一种更 Pythonic 的方法,也许我们可以将其推送到发行版中。如果它能在 cygwin 中开箱即用,那肯定会很方便。

If you are running webdriver from cygwin, the problem is that the path to the profile is still in POSIX format which confuses windows programs. My solution uses cygpath to convert it into Windows format.

in this file/method:
selenium.webdriver.firefox.firefox_binary.launch_browser():

replace:

    self._start_from_profile_path(self.profile.path)

with:

    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)

Since Python is not even close to my primary programming language, if someone can recommend a more pythonic approach maybe we can push it into the distribution. It sure would be handy if it worked in cygwin right out of the box.

陌伤ぢ 2024-11-26 15:37:19

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

I had the same problem and believed it was the wrong combo of selenium / Firefox. Turned out that my .mozilla/ folder permissions were only accessible to the root user. Doing chmod 770 ~/.mozilla/ did the trick. I would suggest making sure this is not the issue before troubleshooting further.

咽泪装欢 2024-11-26 15:37:19

pip install -U selenium

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

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

pip install -U selenium

I had this same issue with Firefox 34.0.5 (Dec 1, 2014) and upgrading Selenium from 2.42.1 to 2.44.0 resolved my issue.

However, I've have since seen this issue again, I think with 2.44.0, and another upgrade fixed it. So I'm wondering if it might be fixed by simply uninstalling and then re-installing. If so, I'm not sure what that would indicate the underlying problem is.

心意如水 2024-11-26 15:37:19

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

I was using selenium 2.53 and firefox version 55.0. I solved this issue by installing the older version of firefox (46.0.1) since selenium 2.53 will not work for firefox version 47.0 & above.

无可置疑 2024-11-26 15:37:19

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

This is not a proper solution but worked for me, if somebody can improve I would be glad to know. I just run my script as root: sudo python myscript.py. I guess I can solve by changing the profile default file or directory could work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文