2

I am using Python 2.7.3, selenium 2.48.0 on Raspbian OS (headless device). Version of Iceweasel/Firefox is 38.4.

I import selenium like this:

from selenium import webdriver

Then I define the driver:

browser = webdriver.Firefox()

When I run this code it runs for about 15 seconds and gives out this error:

Traceback (most recent call last):
  File "Dbfull3.py", line 114, in <module>
    data=getdata()
  File "Dbfull3.py", line 17, in getdata
    browser = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
    self.binary, timeout),
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
    self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 103, in _wait_until_connectable
    raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.

When researching this error I found similar cases from StackOverflowand other places, but many those are from Windows environment or errors come from different packages. One suggested solution was to use different version of Firefox/Iceweasel but I could not find other versions available for my OS.

I have also tried executing my code as root but the result is same.

Desipite the error, every time execute this command new profile gets created to /tmp:

user@host ~/bin $ ls -l /tmp/tmpiV4R0H/
total 11952
drwxr-xr-x 2 user user     4096 Dec 10 18:42 amd64
-rw-r--r-- 1 user user   183494 Dec 10 18:42 blocklist.xml
drwx------ 2 user user     4096 Dec 10 18:43 bookmarkbackups
drwx------ 4 user user     4096 Dec 10 18:42 cache2
-rw------- 1 user user    65536 Dec 10 18:43 cert8.db
-rw------- 1 user user      188 Dec 10 18:42 compatibility.ini
-rw-r--r-- 1 user user   229376 Dec 10 18:42 content-prefs.sqlite
-rw-r--r-- 1 user user   524288 Dec 10 18:43 cookies.sqlite
-rw------- 1 user user     4182 Dec 10 18:43 directoryLinks.json
drwxr-xr-x 3 user user     4096 Dec 10 18:42 extensions
-rw-r--r-- 1 user user      259 Dec 10 18:42 extensions.ini
-rw------- 1 user user     2154 Dec 10 18:43 extensions.json
drwx------ 2 user user     4096 Dec 10 18:42 gmp
-rw------- 1 user user    16384 Dec 10 18:42 key3.db
lrwxrwxrwx 1 user user       16 Dec 10 18:42 lock -> 127.0.1.1:+29581
-rw-r--r-- 1 user user     3319 Dec 10 18:43 mimeTypes.rdf
-rw-r--r-- 1 user user    65536 Dec 10 18:42 permissions.sqlite
-rw-r--r-- 1 user user 10485760 Dec 10 18:43 places.sqlite
-rw-r--r-- 1 user user    32768 Dec 10 18:42 places.sqlite-shm
-rw-r--r-- 1 user user   557496 Dec 10 18:43 places.sqlite-wal
-rw------- 1 user user     5020 Dec 10 18:43 prefs.js
-rw------- 1 user user    16384 Dec 10 18:42 secmod.db
-rw------- 1 user user       53 Dec 10 18:43 sessionCheckpoints.json
drwxr-xr-x 2 user user     4096 Dec 10 18:42 startupCache
drwx------ 2 user user     4096 Dec 10 18:43 userumbnails
-rw-r--r-- 1 user user     3504 Dec 10 18:42 user.js
drwxr-xr-x 2 user user     4096 Dec 10 18:42 webapps
drwxr-xr-x 2 user user     4096 Dec 10 18:42 x86

What could I do to get rid of this error?

EDIT: I have also set up a virtual display to allow Firefox launch. This code is executed before the browser.

from pyvirtualdisplay import Display
display = Display(visible=0, size=(640, 480))
display.start()

I think this part is OK because before adding these lines Selenium gave error about lack of display. With this code Firefox gets started at least enough that it creates some profile files.

Also Firefox starts when I do:

Xvfb :99
export DISPLAY=:99
firefox
(Firefox just sits there, but does not give errors.)

EDIT2: I also tried using Chromium instead of Firefox but that did not work because their webdriver for Selenium does not work with Raspbian.

Madoc Comadrin
  • 498
  • 1
  • 12
  • 27

2 Answers2

1

In the end I solved my problem by using PhantomJS instead of Selenium.

There was not official binary for Raspberry Pi and compling it was very slow so I used this binary from Github: https://github.com/piksel/phantomjs-raspberrypi/

Madoc Comadrin
  • 498
  • 1
  • 12
  • 27
0

Selenium literally launches an instance of firefox

When you launch firefox directly from terminal what happens? As you said this is a headless server, i imagine it doesn't launch.

To get selenium working, you need to be able to run firefox from terminal, without error. Then once you can do that, you can launch it from selenium.

Depending on your use case, python-requests may be a better choice

Remember that firefox needs a DISPLAY to run

triunenature
  • 651
  • 2
  • 7
  • 23