Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

python - Why doesn't Selenium's response have a sessionId?

I'm trying to run Selenium's Firefox webdriver and am getting the error below. I can see that the response does not have a sessionId - the offending line is self.session_id = response['sessionId'] - but I don't know why. I've run this in the following ways and get the same error:

  1. Cygwin, running nosetests
  2. Cygwin directly
  3. Windows, running nosetests
  4. Windows directly

---------------------------------------------------------------------- Traceback (most recent call last): File "C:devoolscygwinhome207013288devprojectsscorpionestunitest_ approve_workflows.py", line 27, in test_login 'password', userid='207013288', test=True) File "C:devoolscygwinhome207013288devprojectsscorpionsrcworkflows.p y", line 20, in login browser = webdriver.Firefox() File "C:devsdksPython33libsite-packagesselenium-2.32.0-py3.3.eggseleniu mwebdriverfirefoxwebdriver.py", line 62, in __init__ desired_capabilities=capabilities) File "C:devsdksPython33libsite-packagesselenium-2.32.0-py3.3.eggseleniu mwebdriver emotewebdriver.py", line 72, in __init__ self.start_session(desired_capabilities, browser_profile) File "C:devsdksPython33libsite-packagesselenium-2.32.0-py3.3.eggseleniu mwebdriver emotewebdriver.py", line 116, in start_session self.session_id = response['sessionId'] nose.proxy.KeyError: 'sessionId' -------------------- >> begin captured logging << -------------------- selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:63801/ hub/session {"sessionId": null, "desiredCapabilities": {"version": "", "browserN ame": "firefox", "platform": "ANY", "javascriptEnabled": true}} --------------------- >> end captured logging << ---------------------

I haven't used Selenium before and I'm not sure where to go from here.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

OK, first of all I'd like to say that I nearly pulled out all my hair trying to fix this. My setup: Python 2.7 Firefox 22.0 Selenium WebDriver 2.33 Windows XP (internet connection via proxy server)

Spotted my problem yet?

Solution:

  • Open the control Panel
  • Internet options
  • Connections
  • LAN Configuration
  • On this page you will probably see the details of your proxy server, complete with a checkbox: "Do not use proxy server for local addresses". This checkbox is probably already selected (as it makes good sense to not use a proxy for local addresses). Unfortunately, Selenium WebDriver appears to ignore this checkbox and it's value. Checked or unchecked, it will detect your proxy server and apply it to all url's (or at least that's what it did in my case.)
  • Click the "Advanced" button, and manually enter "127.0.0.1" in the "Exceptions" box.
  • Save the change.
  • Re-run your test in web driver, hopefully you will no longer see error message that refers to: self.session_id = response['sessionId']

Things that didn't work for me:

Before finding this solution (with the aid of a more experienced engineer) I went through the instructions here:http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#advanceduserinteractions .. for setting/changing/bypassing the proxy. Didn't get me the result I was looking for, though.

I also looked at this: Implementing WebdriverBackedSelenium in Python .. but it speaks of a older version of webdriver, and it suggests removing all the proxy settings system wide, which is an absolute non-starter (as far as I'm concerned).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...