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安裝本身,而不是硒,但在任何情況下,任何幫助將不勝感激。
http://stackoverflow.com/questions/13039530/unable-to-call-firefox-from-selenium-in-python-on-aws-機器可能會有所幫助。 –
謝謝Priyank ..我檢查了一個,但它不是我有同樣的問題。我結束了使用另一個安裝firefox並指向我的PATH env變量。 –