简体   繁体   English

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

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

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

What is wrong?怎么了? How can I resolve this issue?我该如何解决这个问题?

Update:更新:

Selenium team fixed in latest version. Selenium 团队已在最新版本中修复。 For almost all environments the fix is:对于几乎所有环境,修复是:

pip install -U selenium pip 安装-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.不清楚它是在哪个版本修复的(显然是r13122 ),但肯定到 2.26.0(更新时的当前版本)它是固定的。


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

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

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

I had the same issue after upgrading Ubuntu to 12.04.将 Ubuntu 升级到 12.04 后,我遇到了同样的问题。

The issue was on the package side and has been fixed in the latest version of the library.该问题出现在 package 端,并已在最新版本的库中得到修复。 Just update the selenium library.只需更新 selenium 库即可。 For almost all Python environments this is:对于几乎所有 Python 环境,这是:

pip install -U selenium

I faced the same problem with FF 32.0 and Selenium selenium-2.42.1-py2.7.egg.我在使用 FF 32.0 和 Selenium selenium-2.42.1-py2.7.egg 时遇到了同样的问题。 Tried to update selenium, but it is already the latest version.尝试更新selenium,但已经是最新版本了。 The solution was to downgrade Firefox to version 30. Here is the process:解决方案是将 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

This solved all the problems, and this combination works better !这解决了所有问题,并且这种组合效果更好!

As an extension to Jeff Hoye 's answer, a more 'Pythonic' way would be to subclass webdriver.firefox.firefox_profile.FirefoxProfile as follows:作为对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

Then, to create your driver:然后,创建您的驱动程序:

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

If pip install -U selenium doesn't work (it didn't, in my case), try downgrading your Firefox to a previous version.如果pip install -U selenium不起作用(在我的情况下它不起作用),请尝试将 Firefox 降级到以前的版本。

I had Firefox 49.0 and downgraded to 45.0 to make sure the version is supported by selenium.我有 Firefox 49.0 并降级到 45.0 以确保 selenium 支持该版本。 It worked perfectly then.那时它工作得很好。

Here's a fast way to downgrade to Firefox 45.0:这是降级到 Firefox 45.0 的快速方法:

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

Hope this helps.希望这可以帮助。

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.如果您从 cygwin 运行 webdriver,问题是配置文件的路径仍然是 POSIX 格式,这会混淆 windows 程序。 My solution uses cygpath to convert it into Windows format.我的解决方案使用 cygpath 将其转换为 Windows 格式。

in this file/method: selenium.webdriver.firefox.firefox_binary.launch_browser():在这个文件/方法中: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.由于 Python 甚至不接近我的主要编程语言,如果有人可以推荐一种更 Python 的方法,也许我们可以将其推送到发行版中。 It sure would be handy if it worked in cygwin right out of the box.如果它在 cygwin 中开箱即用,它肯定会很方便。

I had the same problem and believed it was the wrong combo of selenium / Firefox.我遇到了同样的问题,并认为这是 selenium / Firefox 的错误组合。 Turned out that my.mozilla/ folder permissions were only accessible to the root user.原来 my.mozilla/ 文件夹权限只能由 root 用户访问。 Doing chmod 770 ~/.mozilla/ did the trick.chmod 770 ~/.mozilla/就行了。 I would suggest making sure this is not the issue before troubleshooting further.我建议在进一步排除故障之前确保这不是问题。

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.我在Firefox 34.0.5 (Dec 1, 2014)遇到了同样的问题,将 Selenium 从2.42.1升级到2.44.0解决了我的问题。

However, I've have since seen this issue again, I think with 2.44.0, and another upgrade fixed it.然而,我已经再次看到这个问题,我认为是 2.44.0,另一个升级修复了它。 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.如果是这样,我不确定这表明潜在的问题是什么。

I was using selenium 2.53 and firefox version 55.0.我使用的是 selenium 2.53 和 firefox 版本 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.我通过安装旧版本的 firefox (46.0.1) 解决了这个问题,因为 selenium 2.53 不适用于 firefox 及以上版本 4。

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 .我只是以 root 身份运行我的脚本: sudo python myscript.py I guess I can solve by changing the profile default file or directory could work.我想我可以通过更改配置文件默认文件或目录来解决。

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

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