1

My python script has the following code:

firefox_profile = webdriver.FirefoxProfile()
self.driver = webdriver.Firefox(firefox_profile=firefox_profile)

When I execute the script from bash it works, but if I call the script from a PHP file, with the following command:

shell_exec("python path_to_the_script");

I receive the exception:

selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /tmp/tmp7Ob0z6/webdriver-py-profilecopy If you specified a log_file in the FirefoxBinary constructor, check it for details.

I've also tried to set the profile manually, like this:

 firefox_profile = webdriver.FirefoxProfile(profile_directory='path_to_the_profile_dir')

But nothing changed, while if I set the profile directory path like this:

firefox_profile = webdriver.FirefoxProfile(profile_directory='path_to_the_profile_dir')
firefox_profile.profile_dir = 'path_to_the_profile_dir'

The exception error changes to this:

selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: path_to_the_profile_dir If you specified a log_file in the FirefoxBinary constructor, check it for details.

I've set the permissions to 777 for all the involved directories, and also tried to override the FirefoxBinary.launch_browser function so that it uses a greater timeout value, but id did not work. I'm using Python 2.7, Selenium 2.53.6 and Firefox 46.0.1

Firefox is working in headless mode, through Xvfb and pyvirtualdisplay.

miczza
  • 165
  • 2
  • 9

2 Answers2

1

This happens because you have updated firefox to a version that's no longer supported by selenium.

So to fix this you have 2 options.

  1. Downgrade your firefox to an older version then 47
  2. Update Selenium and Install geckodriver (recommended and easy)


If you have ubuntu follow this fix below:
1. Update selenium with "sudo pip install -U selenium"
2. Download the geckodriver from github --> Gecko Github Link
3. Extract the tar.gz folder and move the gecko executable to /usr/local/bin
4. Now open your terminal and enter this command:
export PATH=$PATH:/usr/local/bin/geckodriver

That should fix the issue... atleast it worked for me.

My Source: StackOverflow - Geckodriver

prive
  • 11
  • 2
  • According to the [release notes](https://github.com/mozilla/geckodriver/releases), Geckodriver v0.19.0 recommends Selenium 3.5+ (and Firefox 55+), Geckodriver v0.16.0 requires Selenium 3.4+ and Geckodriver v0.15.0 requires Selenium 3.3+. Some distros are still on the 2.x versions of Selenium in their packages (e.g. Fedora Core 27's `python2-selenium` package is 2.53.6), so if you use such a package you might want to uninstall it and do `sudo pip install selenium` instead. – Silas S. Brown May 01 '18 at 14:32
0

If that didn't fix your issue check your firefox profile name

like this

fp = webdriver.FirefoxProfile('/home/YOUR_USERNAME/.mozilla/firefox/YOUR_PROFILE_NAME.default')
driver = webdriver.Firefox(firefox_profile=fp)

To find your firefox profile name open your file browser and enable "show hidden files" go to "Home/.mozilla/firefox" and you'll see your firefox profile folder.

I hope that solved your issue

prive
  • 11
  • 2