Selenium WebDriver无法加载配置文件 [英] Selenium WebDriver can't load profile

查看:258
本文介绍了Selenium WebDriver无法加载配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Selenium WebDriver启动Firefox,并得到以下错误:

$ p $ --------- -------------------------------------------------- ----------------
WebDriverException Traceback(最近一次调用的最后一个)
< ipython-input-10-9e1140c380e1> in< module>()
----> 1 t = tweepi.Tweepi(username,0,profile_name)

/home/ubuntu/twitter/tweepi.pyc in __init __(self,username,threadid,profilename)
22 profile = webdriver .FirefoxProfile(profilename)
23 self.logger.debug('launch firefox')
---> 24 self.driver = webdriver.Firefox(firefox_profile = profile)
25 else:
26 self.driver = webdriver.Firefox()

/ usr / local / lib / python2 ._ / __init __(self,firefox_profile,firefox_binary,timeout,capabilities,proxy)
57 RemoteWebDriver .__ init __(self,$ b $ 58 command_executor = ExtensionConnection (127.0.0.1,self.profile,
---> 59 self.binary,timeout),
60 desired_capabilities = capabilities,
keep_alive = True)

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.pyc in __init __(self,host,firefox_profile,firefox_binary,timeout)
self.profile。 add_extension()
46
---> 47 self.binary.launch_browser(self.profile)
48 _URL =http://%s:%d / hub%(HOST,PORT)
49 RemoteConnection .__ init __(

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc in launch_browser(self,profile)
62
63 self._start_from_profile_path(self .profile.path)
---> 64 self._wait_until_connectable()
65
66 def kill(self):

/ usr / local / lib /python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc in _wait_until_connectable(self)$ b $ 106 raise WebDriverException(无法加载配置文件。配置文件
107Dir:% (
- > 108 self.profile.path,self._get_firefox_output()))
109 count + = 1
110 time.sleep(1 )

WebDriverException:消息:无法加载配置文件文件目录:/ tmp / tmp4nBIo5 / webdriver-py-profilecopy Firefox输出:无

其他类似的线程,我在这里找到的stackoverflow说,解决方案是通过使用命令更新硒


$ b


pip install -U selenium


这解决了本地计算机上的问题,但问题仍然存在于AWS上的远程计算机上。这两台电脑具有相同的Firefox版本,都具有最新的硒,他们甚至有〜/ .mozilla / firefox上完全相同的配置文件夹。



任何建议吗?

编辑:

我可以在没有配置文件的情况下启动Firefox。也就是说,做

$ pre $ w $ webdriver.Firefox
code $


$ b

可以工作,而

$ $ $ $ $ $ c $ profile_name ='/ home / ubuntu / .mozilla / firefox / amozqob6.profile6'
profile = webdriver.FirefoxProfile(profile_name)
w = webdriver.Firefox(firefox_profile = profile)

得到上述错误信息。

EDIT2:

直接运行Firefox可执行文件:

  firefox -profile〜/ .mozilla / firefox / amozqob6.profile6 


解决方案

帮助我指定了二进制文件firefox的显式路径

  from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 
binary = FirefoxBinary(/ home / teddy / firefox / firefox)
driver = webdriver.Firefox(firefox_binary = binary)


I try firing up Firefox using Selenium WebDriver and get the following error:

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-10-9e1140c380e1> in <module>()
----> 1 t = tweepi.Tweepi(username, 0, profile_name)

/home/ubuntu/twitter/tweepi.pyc in __init__(self, username, threadid, profilename)
     22             profile = webdriver.FirefoxProfile(profilename)
     23             self.logger.debug('launching firefox')
---> 24             self.driver = webdriver.Firefox(firefox_profile = profile)
     25         else:
     26             self.driver = webdriver.Firefox()

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.pyc in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy)
     57         RemoteWebDriver.__init__(self,
     58             command_executor=ExtensionConnection("127.0.0.1", self.profile,
---> 59             self.binary, timeout),
     60             desired_capabilities=capabilities,
     61             keep_alive=True)

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.pyc in __init__(self, host, firefox_profile, firefox_binary, timeout)
     45         self.profile.add_extension()
     46 
---> 47         self.binary.launch_browser(self.profile)
     48         _URL = "http://%s:%d/hub" % (HOST, PORT)
     49         RemoteConnection.__init__(

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc in launch_browser(self, profile)
     62 
     63         self._start_from_profile_path(self.profile.path)
---> 64         self._wait_until_connectable()
     65 
     66     def kill(self):

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc in _wait_until_connectable(self)
    106                 raise WebDriverException("Can't load the profile. Profile "
    107                       "Dir: %s Firefox output: %s" % (
--> 108                           self.profile.path, self._get_firefox_output()))
    109             count += 1
    110             time.sleep(1)

WebDriverException: Message: "Can't load the profile. Profile Dir: /tmp/tmp4nBIo5/webdriver-py-profilecopy Firefox output: None" 

Now, every other similar thread I found here on stackoverflow says the solution is to update selenium by using the command

pip install -U selenium

This fixed the problem on my local computer, but the problem persists on my remote computer on AWS. These two computers have the same Firefox version, both have selenium up-to-date and they even have the exact same profile folder on ~/.mozilla/firefox.

Any suggestions?

EDIT:

I can start Firefox without the profile. That is, doing

w = webdriver.Firefox()

works, whereas doing

profile_name = '/home/ubuntu/.mozilla/firefox/amozqob6.profile6'
profile = webdriver.FirefoxProfile(profile_name)
w = webdriver.Firefox(firefox_profile=profile)

gets the above error message.

EDIT2:

Running the Firefox executable directly works:

firefox -profile ~/.mozilla/firefox/amozqob6.profile6

解决方案

helped me to specify an explicit path to the binary file firefox

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary("/home/teddy/firefox/firefox")
driver = webdriver.Firefox(firefox_binary=binary)

这篇关于Selenium WebDriver无法加载配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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