Question

This is my code:

 from selenium import webdriver
 from selenium.webdriver.common.keys import Keys

 browser = webdriver.Firefox()

 browser.get('http://www.yahoo.com')
 assert 'Yahoo!' in browser.title

 elem = browser.find_element_by_name('p')  # Find the search box
 elem.send_keys('seleniumhq' + Keys.RETURN)

 browser.quit()

But I am getting an error for it:

        root@debian:~# python python_org_search.py
        Traceback (most recent call last):
          File "python_org_search.py", line 4, in <module>
            browser = webdriver.Firefox()
          File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
            self.binary, timeout),
          File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
            self.binary.launch_browser(self.profile)
          File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 61, in launch_browser
            self._wait_until_connectable()
          File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
            self._get_firefox_output())
        selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'

Is this error because I am using an CLI (Command Line Interface) Operating system (DEBIAN server 6.0.1)

Was it helpful?

Solution

Most browsers need to run in an x display. I solve this by running xvfb (apt-get install xvfb).

Then python needs to be able to use this display: https://pypi.python.org/pypi/PyVirtualDisplay

Start the display, then initialize the webdriver browser and test away...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top