0

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)

9
  • welcome. What version of Selenium do you have installed? Commented Apr 17, 2014 at 11:58
  • can you post what you get when you type into the terminal: which firefox Commented Apr 17, 2014 at 12:00
  • @Tweek usually appears the same error in browser terminal. But the author can reveal the terminal code. Commented Apr 17, 2014 at 12:01
  • @Tweek and fiskerXO thanks for the comments.. root@debian:~# which firefox /usr/bin/firefox Commented Apr 17, 2014 at 12:03
  • @fiskerXO how can i chk the selenium version it tried this..but it gives me this root@debian:~# selenium --version -bash: selenium: command not found Commented Apr 17, 2014 at 12:06

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

2 Comments

yes its done using PyVirtualDisplay the code is working perfect ..but only one thing when the test passes it displays me nothing and if it has an error then it show me a message like ASSERTIONERROR.. how can i get it like 10 TEST pass or TEST FAIL. or something little understanable
You'll need to use a test runner. There is one in the standard library called unittest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.