Selenium:FirefoxProfile失败,出现not found异常

2024-10-01 09:34:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码,尽管我设置了profile_directoryFirefox 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'));

例外代码:

^{pr2}$

我做错了什么?或者需要为selenium添加特定的配置设置吗?在


Tags: 代码文件夹httphomeportnetworkprofiledirectory
1条回答
网友
1楼 · 发布于 2024-10-01 09:34:50

我也有同样的问题。因为FF5没有“用户.js“在个人资料中->我们不必阅读它。在

打开selenium/webdriver/firefox/firefox_py.py剖面并在def\u read_existing_userjs(self)之后添加try except,如下所示:

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)

相关问题 更多 >