簡體   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