2011-07-11 95 views
2

我有下面的代碼,雖然我設置profile_directory火狐的webdriver仍試圖存儲/tmp文件夾中設置硒:FirefoxProfile失敗,未發現異常

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')); 

異常代碼

 

    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' 

我在做什麼錯誤或我需要爲硒添加特定的配置設置?

蘇丹

+0

確實/家庭/蘇丹/配置文件包含多個配置文件? –

+0

是的,它應該包含多個配置文件,但現在它仍然保存配置文件在/ tmp中,原因是我嘗試使用線程來測試網站 – sultan

+0

不應該指向一個配置文件文件夾而不是包含多個配置文件的文件夾? –

回答

2

我有同樣的問題。由於FF5在配置文件中沒有「user.js」 - >我們不必閱讀它。

如此開放硒/ webdriver的/火狐/ firefox_profile.py並添加嘗試除了高清_read_existing_userjs(個體經營),這樣以後:

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) 
+0

也可以這樣修復http://code.google.com/p/selenium/source/detail?r=12909 – sultan