Selenium:FirefoxProfile失败,未找到异常 [英] Selenium: FirefoxProfile fails with not found exception

查看:441
本文介绍了Selenium:FirefoxProfile失败,未找到异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码虽然设置了 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'));

例外代码

 

文件/home/sultan/Repository/Django/monitor/app/utils.py,第79行,开始
request.perform(scan = scan,schedule = schedule)
执行$ b的文件/home/sultan/Repository/Django/monitor/app/request.py,第230行$ b profile1 = FirefoxProfile(profile_directory ='/ home / sultan / profiles')
文件/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_profile.py,行97,在__init__
self._read_existing_userjs()
文件/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_profile.py,第178行,在_read_existing_userjs
f = open(os.path.join(self.profile_dir,'user.js'),r)
IOError:[Errno 2]没有这样的文件或目录:'/ tmp / webdriver- py-profilecopy / user.js'



我在做什么错了,或者我需要添加一个特定的配置硒的问题?

苏丹

解决方案

我有同样的问题。由于FF5在配置文件中没有user.js - >我们不必读取它。


$ b

打开 selenium / webdriver / firefox / firefox_profile.py 并在def _read_existing_userjs(self)之后添加 ,像这样:
$ b $ pre $ def $ _read_existing_userjs(self):
try:
f = open(os.path .join(self.profile_dir,'user.js'),r)
除了IOError,e:
print我们没有在你的配置文件中找到user.js,但是没关系
return
$ b tmp_usr = f.readlines()
f.close()
for tmp_usr:
matches = re.search('user_pref \((。*),\s(。*)\)',usr)
self.default_preferences [matches.group(1)] = matches.group(2)


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?

Sultan

解决方案

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)

这篇关于Selenium:FirefoxProfile失败,未找到异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆