简体   繁体   English

Selenium:FirefoxProfile 失败,未找到异常

[英]Selenium: FirefoxProfile fails with not found exception

I've the following code, though I set the profile_directory Firefox webdriver still attempts to store setting within the /tmp folder我有以下代码,尽管我设置了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'));

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?我做错了什么还是需要为 selenium 添加特定的配置设置?

I have same problem.我有同样的问题。 As FF5 doesn't have "user.js" in profile -> we don't have to read it.由于 FF5 在配置文件中没有“user.js”-> 我们不必阅读它。

so open selenium/webdriver/firefox/firefox_profile.py and add try except after def _read_existing_userjs(self), like this:所以打开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.

相关问题 Selenium:FirefoxProfile 异常无法加载配置文件 - Selenium: FirefoxProfile exception Can't load the profile FirefoxProfile 与 Selenium 的私有模式 - FirefoxProfile with private mode for Selenium selenium没有在FirefoxProfile中设置downloaddir - selenium doesn't set downloaddir in FirefoxProfile 如何通过Selenium和Python加载现有的FirefoxProfile - How to load a existing FirefoxProfile through Selenium and Python 模块“selenium.webdriver”没有属性“firefoxprofile” - module 'selenium.webdriver' has no attribute 'firefoxprofile' 尝试调用它时超时异常失败 Selenium - Timeout Exception fails when trying to call it Selenium 消息:错误:轮询更改失败:在通过 Selenium 和 FirefoxProfile 下载文件时尝试获取资源时出现网络错误 - Message: Error: Polling for changes failed: NetworkError when attempting to fetch resource while downloading file through Selenium and FirefoxProfile 如何使用 FirefoxProfile 或 FirefoxOptions 通过 Selenium 设置 Firefox 浏览器的窗口位置 - How to set window position of Firefox browser through Selenium using FirefoxProfile or FirefoxOptions suds脚本失败,出现异常异常:导入的架构失败,找不到记录程序“ suds.xsd.sxbasic”的处理程序 - suds script fails with exception Exception: imported schema failed, No handlers could be found for logger “suds.xsd.sxbasic” Firefox selenium 驱动程序在无头模式下失败,其中 chrome 由于超时异常而工作 - Firefox selenium driver fails in headless mode where chrome works due to timeout exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM