Python Selenium:FirefoxProfile失败,未找到异常
我有以下代码,尽管我设置了Python Selenium:FirefoxProfile失败,未找到异常,python,firefox,selenium,webdriver,Python,Firefox,Selenium,Webdriver,我有以下代码,尽管我设置了profile\u目录firefoxwebdriver仍然试图将设置存储在/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('p
profile\u目录
firefoxwebdriver仍然试图将设置存储在/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\u profile.py并在def\u read\u existing\u 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)
/home/sultan/profiles是否包含多个配置文件?是的,它应该包含多个配置文件,但目前它仍将配置文件保存在/tmp中,原因是我尝试使用线程测试网站,您是否指向一个配置文件文件夹而不是包含多个配置文件的文件夹?是的,此文件夹包含多个配置文件,我不得不在更多的方法中加入try-except-block,以使其发挥作用,即使在9年以上的时间里,它仍然像一种魅力一样发挥作用。