11

I have a small test python script that uses Selenium and PhantomJS. Python version is 2.7 and PhantomJS is 1.9.2. I later plan to use this with BeautifulSoup for accessing a financial website.

My python script looks like this -

from selenium import webdriver
phantomJSPath = "C:\my working dir\\Lib\phantomjs.exe"
browser = webdriver.PhantomJS(executable_path=phantomJSPath)

After executing I get the below error -

File "C:\my working dir\Test.py", line 32, in run

browser = webdriver.PhantomJS(executable_path=phantomJSPath)
File "C:\Python27\lib\site-   packages\selenium\webdriver\phantomjs\webdriver.py", line 56, in __init__
desired_capabilities=desired_capabilities)
File "C:\Python27\lib\site-  packages\selenium\webdriver\remote\webdriver.py", line 87, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 136, in   start_session
'desiredCapabilities': desired_capabilities,
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 196, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 102, in check_response
value = json.loads(value_json)
File "C:\Python27\lib\json\__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Would anyone know why I am getting this error?

2
  • PhantomJS 1.9.2 is really old and there may be an issue with an incompatibility with GhostDriver and the selenium library. Try to update to a newer PhantomJS version like 2.0.0, 1.9.8 or 1.9.7. Commented Oct 21, 2015 at 7:21
  • 1
    Which version of Selenium are you using? Commented Oct 25, 2015 at 13:27

3 Answers 3

2

Sorry to answer my own bounty, but for those who might possibly run into similar issues: the http_proxy environment variable does not play well with phantomjs and selenium. I removed it and all worked as it should have.

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

Comments

1

I have a similar issue (transient) when calling browser.close() with selenium 1.9.8 running on Ubunto 15:

  File "propertunity/soup/Soup.py", line 121, in get...
    browser.close()
  File "/home/<user>/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 473, in close
    self.execute(Command.CLOSE)
  File "/home/<user>/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "/home/<user>/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 102, in check_response
    value = json.loads(value_json)
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

There seem to be a known issue with close() not really cleaning up after you finish with the browser. Try changing the close() to quit and setting the browser object to None.

1 Comment

In reference to the above bounty, this does not appear to be the same issue (exactly).
1

You should give extra paramters to define browser, it tries to assign desired_capabilities=desired_capabilities which expects a json object. You can do it like following:

from selenium import webdriver
phantomJSPath = "C:\my working dir\\Lib\phantomjs.exe"
desiredCap = {'platform': 'ANY', 'browserName': 'phantomjs', 'version': '', 'javascriptEnabled': True}
browser = webdriver.PhantomJS(executable_path=phantomJSPath, port=0, desired_capabilities=desiredCap)

1 Comment

I think there is already a default to desired_capabilities which is a dictionary.

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.