selenium python not working with phantomjs
Question: I have installed phantomjs with npm and selenium-python via python.

Everything works properly with Headless Firefox, but not with phantomjs.

Here is the code.

    
    
    In [1]: from selenium import webdriver
    
    In [2]: browser = webdriver.PhantomJS()
    
    In [3]: browser.get('http://www.google.com/')
    
    ---------------------------------------------------------------------------
    CannotSendRequest                         Traceback (most recent call last)
    <ipython-input-5-a95426e05380> in <module>()
    ----> 1 browser.get('http://www.google.com/')
    
    /home/asit/pyrepo/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyc in get(self, url)
        174         Loads a web page in the current browser session.
        175         """
    --> 176         self.execute(Command.GET, {'url': url})
        177 
        178     @property
    
    /home/asit/pyrepo/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyc in execute(self, driver_command, params)
        160 
        161         params = self._wrap_value(params)
    --> 162         response = self.command_executor.execute(driver_command, params)
        163         if response:
        164             self.error_handler.check_response(response)
    
    /home/asit/pyrepo/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.pyc in execute(self, command, params)
        353         path = string.Template(command_info[1]).substitute(params)
        354         url = '%s%s' % (self._url, path)
    --> 355         return self._request(url, method=command_info[0], data=data)
        356 
        357     def _request(self, url, data=None, method=None):
    
    /home/asit/pyrepo/env/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.pyc in _request(self, url, data, method)
        381             headers["Authorization"] = "Basic %s" % auth
        382 
    --> 383         self._conn.request(method, parsed_url.path, data, headers)
        384         resp = self._conn.getresponse()
        385         statuscode = resp.status
    
    /usr/lib/python2.7/httplib.pyc in request(self, method, url, body, headers)
        956     def request(self, method, url, body=None, headers={}):
        957         """Send a complete request to the server."""
    --> 958         self._send_request(method, url, body, headers)
        959 
        960     def _set_content_length(self, body):
    
    /usr/lib/python2.7/httplib.pyc in _send_request(self, method, url, body, headers)
        984             skips['skip_accept_encoding'] = 1
        985 
    --> 986         self.putrequest(method, url, **skips)
        987 
        988         if body and ('content-length' not in header_names):
    
    /usr/lib/python2.7/httplib.pyc in putrequest(self, method, url, skip_host, skip_accept_encoding)
        854             self.__state = _CS_REQ_STARTED
        855         else:
    --> 856             raise CannotSendRequest()
        857 
        858         # Save the method we use, we need it later in the response phase
    
    CannotSendRequest: 
    

Any solution to this ?


Answer: Make sure you're at least at PhantomJS 1.8 They didn't support webdriver
connections until that version. I know my package manager had a much older
version when I was going through this yesterday.
<http://phantomjs.org/release-1.8.html>

