102

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?

Community
  • 1
  • 1
sultan
  • 5,978
  • 14
  • 59
  • 103

10 Answers10

137

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rachel
  • 2,858
  • 2
  • 26
  • 30
  • 3
    Adding a `sudo` is required if not logged in as root. Anyway, this was a lifesaver! Thanks!! – Abhranil Das May 03 '13 at 17:52
  • Yes it helps to fix WebDriverException: Message: 'Can\'t load the profile. – tom joy Dec 19 '13 at 09:41
  • 5
    @AbhranilDas You don't need `sudo` if you're using a `virtualenv` (which you probably should use). – Kos Dec 30 '13 at 10:41
  • At first I was unable to upgrade: pip install -U selenium told me I had the latest version, even though it was 2.25.0. I'm on Ubuntu 14.04. I had to go to the package manager (sudo synaptic) and remove selenium there. Then I had to do sudo pip uninstall selenium followed by sudo pip install selenium. That got me to version 2.42.1. – Steve Saporta Sep 08 '14 at 16:04
  • Even after I succeeded in installing selenium 2.42.1, the problem persisted. Then I followed user1757247's suggestion to downgrade Firefox to version 30.0, and that solved the problem. – Steve Saporta Sep 08 '14 at 16:05
  • 7
    No, this solution does not works with Firefox 45.0b and latest Selenium (2.5.1) – Alex G.P. Feb 02 '16 at 10:32
  • 1
    @AlexG.P. I first wrote the answer to this question 4.5 years ago. I suspect that enough time has passed that it might be worth raising a new question. If you do, please include a reference to this question and: a) the Firefox and Selenium versions you gave above; b) your OS; c) your version of pip. I'd guess that your problem might be related to the pip version, because that has changed over the last 5 years. – Rachel Feb 03 '16 at 20:33
  • @AlexG.P.: Perhaps this is your problem: https://github.com/SeleniumHQ/selenium/issues/1300 It was my problem when running on a slow computer (Raspberry Pi). – Alex Feb 04 '16 at 04:20
32

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
user1380597
  • 345
  • 3
  • 3
  • Don't know why, but having selenium 2.28.0 I have same issue with FireFox 22.0 and 23.0 on Ubuntu. Only downgrading firefox to 18.0 works fine for me (never checked other versions). – Dmitry Sep 10 '13 at 17:31
26

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 !

Mijo
  • 611
  • 8
  • 10
8

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())
Joel Cross
  • 1,400
  • 15
  • 22
5

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.

Chris
  • 1,173
  • 11
  • 19
4

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.

Jeff Hoye
  • 580
  • 5
  • 11
3

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.

chillwx
  • 31
  • 3
1

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.

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
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.

Rashid
  • 65
  • 4
-1

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.