2014-01-20 106 views
1

我剛剛使用pip安裝了硒。當我啓動一個django shell時,我可以從selenium導入模塊。 而下面的語句將失敗:硒(用python/django)無法啓動firefox瀏覽器實例

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安裝本身,而不是硒,但在任何情況下,任何幫助將不勝感激。

+0

http://stackoverflow.com/questions/13039530/unable-to-call-firefox-from-selenium-in-python-on-aws-機器可能會有所幫助。 –

+0

謝謝Priyank ..我檢查了一個,但它不是我有同樣的問題。我結束了使用另一個安裝firefox並指向我的PATH env變量。 –

回答

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" 

我最後不得不火狐的新安裝做(我注意到以前的版本太舊,我沒有權限升級它),指着我的PATH變量使用它:

setenv PATH /path/to/new/firefox/:$PATH 
相關問題