Selenium WebDriver无法加载配置文件。

4
我尝试使用Selenium WebDriver启动Firefox,但出现以下错误:
---------------------------------------------------------------------------
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" 

现在,我在Stack Overflow上找到的每个类似的线程都说解决方法是使用以下命令更新selenium:

pip install -U selenium

这在我的本地计算机上解决了问题,但在我的AWS远程计算机上问题仍然存在。这两台计算机具有相同的Firefox版本,均已更新为最新的selenium版本,甚至它们在 ~/.mozilla/firefox 中拥有完全相同的配置文件夹。

有任何建议吗?

编辑:

我可以在没有配置文件的情况下启动Firefox。也就是说,执行以下操作:

w = webdriver.Firefox()

工作,而不是做事

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

收到以上错误信息。

编辑2:

直接运行Firefox可执行文件可以正常工作:

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

@SilasRay确实,它有效。我更新了问题。有什么建议吗? - user1950164
@SilasRay 对不起,没错。一个是32位,另一个是64位。 - user1950164
那么,从另一个方向来尝试一下。尝试使用-profile标志在远程终端上启动Firefox,并提供自定义配置文件的路径。如果可以正常工作,那么问题可能出在Python或Selenium上。如果无法正常工作,则可能会从Firefox中获得更有用的错误信息,以指出配置文件存在的问题。 - Silas Ray
@SilasRay 我刚试了一下,它确实可以工作,就像你说的那样,这意味着问题出在 Python 或 Selenium 上。不过这并不奇怪,因为就像我说的,在我的本地环境中,只需升级 Selenium 就可以解决问题。现在我要尝试远程 64 位环境了,这可能需要一些时间。 - user1950164
我建议尝试创建另一个配置文件。之后,可以卸载Selenium/Python/Firefox。这是一个比较难以诊断的问题,特别是没有访问权限和大量在线研究的情况下。 - Silas Ray
显示剩余5条评论
1个回答

3

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接