【问题标题】:Selenium not working on OpenSUSE 42.1: The browser appears to have exited before we could connect [duplicate]Selenium 在 OpenSUSE 42.1 上不起作用:浏览器似乎在我们可以连接之前已经退出 [重复]
【发布时间】:2016-10-16 07:27:04
【问题描述】:

我正在尝试在具有 Gnome 桌面和 Firefox 47 的本地计算机上使用 Python 3.4 运行 Selenium。但是,最基本的任务已经失败,即打开浏览器窗口。我知道这个问题已经在几个 SO 帖子上被问过了,但没有一个答案能解决问题。

我只是用pip install selenium 安装了 Selenium。当我跑步时

from selenium import webdriver
driver= webdriver.Firefox()

我得到以下回溯:

WebDriverException                        Traceback (most recent call last)
<ipython-input-2-b517b01341f3> in <module>()
----> 1 driver= webdriver.Firefox()

/usr/lib/python3.4/site-packages/selenium/webdriver/firefox/webdriver.py in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy, executable_path, firefox_options)
     79 
     80             executor = ExtensionConnection("127.0.0.1", self.profile,
---> 81                                            self.binary, timeout)
     82             RemoteWebDriver.__init__(self,
     83                 command_executor=executor,

/usr/lib/python3.4/site-packages/selenium/webdriver/firefox/extension_connection.py in __init__(self, host, firefox_profile, firefox_binary, timeout)
     49         self.profile.add_extension()
     50 
---> 51         self.binary.launch_browser(self.profile, timeout=timeout)
     52         _URL = "http://%s:%d/hub" % (HOST, PORT)
     53         RemoteConnection.__init__(

/usr/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py in launch_browser(self, profile, timeout)
     66 
     67         self._start_from_profile_path(self.profile.path)
---> 68         self._wait_until_connectable(timeout=timeout)
     69 
     70     def kill(self):

/usr/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py in _wait_until_connectable(self, timeout)
     96             if self.process.poll() is not None:
     97                 # Browser has exited
---> 98                 raise WebDriverException("The browser appears to have exited "
     99                       "before we could connect. If you specified a log_file in "
    100                       "the FirefoxBinary constructor, check it for details.")

WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

我已经尝试使用pyvirtualdisplay 并设置$DISPLAY 环境变量,但没有任何帮助。

【问题讨论】:

  • 你使用的是firefox 47.0吗?

标签: python selenium selenium-webdriver


【解决方案1】:

自从 firefox 更新到 47 版后,selenium 不再运行。解决方法是using Marionette。这也是 Mozilla 推荐的。


您可以使用的替代方法是使用较旧的 firefox 版本:

您可以下载二进制文件here 并在此处使用:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)

【讨论】:

  • Firefox 47 还有其他问题吗?即使使用似乎适用于大多数任务的新驱动程序,我也无法从下拉列表中选择元素。
  • 我更新了我的答案。你可以试试看。
  • 我已经下载了二进制文件,但是当我启动它时,它仍然说它是 Firefox 47。
  • 你已经设置了binary = FirefoxBinary('path/to/firefox/firefox') ?
  • 好的,当我执行终端时它启动了 47,但是当在 selenium 中使用它时,它启动旧版本并且选择实际上正在工作。非常感谢!
猜你喜欢
  • 2021-11-14
  • 2014-11-22
  • 2015-01-31
  • 1970-01-01
  • 2019-02-18
  • 2013-09-20
  • 2016-10-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多