簡體   English   中英

Selenium:FirefoxProfile 失敗,未找到異常

[英]Selenium: FirefoxProfile fails with not found exception

我有以下代碼,盡管我設置了profile_directory Firefox webdriver 仍然嘗試將設置存儲在/tmp文件夾中

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'

我做錯了什么還是需要為 selenium 添加特定的配置設置?

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

所以打開selenium/webdriver/firefox/firefox_profile.py並在 def _read_existing_userjs(self) 之后添加嘗試,如下所示:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM