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变量。 –