Selenium无法在OpenSUSE 42.1上运行:在我们连接

时间:2016-06-15 09:12:08

标签: python selenium selenium-webdriver

我正在尝试使用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环境变量,但没有任何帮助。

1 个答案:

答案 0 :(得分: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)