3

I've the following code, though I set the profile_directory Firefox webdriver still attempts to store setting within the /tmp folder

profile = FirefoxProfile(profile_directory = '/home/sultan/profiles')
profile.set_preference('network.proxy.http', scheme);
profile.set_preference('network.proxy.http_port', self.proxy.get('port'));

Exception Code:

File "/home/sultan/Repository/Django/monitor/app/utils.py", line 79, in start
    request.perform(scan = scan, schedule = schedule)
File "/home/sultan/Repository/Django/monitor/app/request.py", line 230, in perform
    profile1 = FirefoxProfile(profile_directory = '/home/sultan/profiles')
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 97, in __init__
    self._read_existing_userjs()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 178, in _read_existing_userjs
    f = open(os.path.join(self.profile_dir, 'user.js'), "r")
IOError: [Errno 2] No such file or directory: '/tmp/webdriver-py-profilecopy/user.js'

What am I doing wrong or do I need to add a specific configuration settings for selenium?

David Rogers
  • 2,601
  • 4
  • 39
  • 84
sultan
  • 5,978
  • 14
  • 59
  • 103

1 Answers1

3

I have same problem. As FF5 doesn't have "user.js" in profile -> we don't have to read it.

so open selenium/webdriver/firefox/firefox_profile.py and add try except after def _read_existing_userjs(self), like this:

def _read_existing_userjs(self):
    try:
        f = open(os.path.join(self.profile_dir, 'user.js'), "r")
    except IOError, e:
        print "We didn't find user.js in your profile, but that is ok"
        return

    tmp_usr = f.readlines()
    f.close()
    for usr in tmp_usr:
        matches = re.search('user_pref\("(.*)",\s(.*)\)', usr)
        self.default_preferences[matches.group(1)] = matches.group(2)
Anton Shishkov
  • 188
  • 2
  • 8
  • Although, I had to add try except block to couple of more methods to make it work, it worked like a charm even after 9+ years. – Nishith Shah Sep 13 '20 at 19:38