selenium(用python / django)无法启动firefox浏览器实例

时间:2014-01-20 21:35:55

标签: python django firefox testing selenium

我刚刚使用pip安装了selenium。当我启动django shell时,我可以从selenium导入模块。 但是,以下声明失败:

self.browser = webdriver.Firefox()

出现以下错误:

Traceback (most recent call last):
  File "/opt/my_apps/cpns/core/tests.py", line 771, in setUp
    self.browser = webdriver.Firefox()
  File "/opt/my_apps/cpns/build/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.binary, timeout),
  File "/opt/my_apps/cpns/build/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "/opt/my_apps/cpns/build/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 61, in launch_browser
    self._wait_until_connectable()
  File "/opt/my_apps/cpns/build/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
    self._get_firefox_output())
WebDriverException: Message: "The browser appears to have exited before we could connect. The output was: XPCOMGlueLoad error for file /usr/bin/libxpcom.so:\n/usr/bin/libxpcom.so: cannot open shared object file: No such file or directory\nCouldn't load XPCOM.\n"

我正在尝试执行的代码非常基本。我在网上复制了它:

class GoogleTestCase(TestCase):

    def setUp(self):
        self.browser = webdriver.Firefox()
        self.addCleanup(self.browser.quit)

    def testPageTitle(self):
        self.browser.get('http://www.google.com')
        self.assertIn('Google', self.browser.title)

我认为它更多地与firefox安装本身而不是selenium有关,但无论如何,任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

由于问题似乎与使用共享对象有关

WebDriverException: Message: "The browser appears to have exited before we could connect. The output was: XPCOMGlueLoad error for file /usr/bin/libxpcom.so:\n/usr/bin/libxpcom.so: cannot open shared object file: No such file or directory\nCouldn't load XPCOM.\n"

我最终安装了一个新的firefox(我注意到以前的版本太旧而且我没有权限升级它),并指向我的PATH变量来使用它:

setenv PATH /path/to/new/firefox/:$PATH