本文介绍了为什么Selenium的响应没有sessionId?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行Selenium的Firefox网络驱动程序,并得到以下错误。我可以看到响应没有 sessionId - 违规行是 self。 session_id = response ['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,运行nosetests

  2. Cygwin直接

  3. Windows,正在运行nosetests

  4. 直接Windows

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


----------------------------------- -----------------------------------
回溯(最近一次呼叫):
文件C:\dev\tools\cygwin\home\207013288\dev\projects\scorpion\test\unit\test_
approve_workflows.py,第27行,在test_login
'password',userid ='207013288',test = True)
文件C:\dev\tools\cygwin\home\207013288\dev\projects\\ \\ scorpion \src\workflows.p
y,第20行,在登录
browser = webdriver.Firefox()
文件C:\dev\sdks\Python33\\ \\ lib \site-packages\selenium-2.32.0-py3.3.egg\seleniu
m\webdriver\firefox\webdriver.py,第62行,位于__init__
desired_capabilities = capabilities)
文件C:\dev\sdks\Python33\lib\site-packages\selenium-2.32.0-py3.3.egg\seleniu
m\ webdriver \remote\webdriver.py,第72行,在__init__
self.start_session(desired_capabilities,browser_profile)
文件C:\dev\sdks\Python33\lib\ site-packages\selenium-2.32.0-py3.3.egg\seleniu
m\webdriver\remote\webdriver.py,第116行,在start_session
self.session_id = response ['sessionId']
nose.proxy.KeyError:'sessionId'
-------------------->>开始捕获日志< --------------------
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}}
--------------------->>结束捕获的日志< ---------------------

t以前使用硒,我不知道从这里去哪里。

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

推荐答案

好的,首先我想说几乎拉出我的头发,试图解决这个问题。
我的设置:
Python 2.7
Firefox 22.0
Selenium WebDriver 2.33
Windows XP(通过代理服务器连接互联网)

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.7Firefox 22.0Selenium WebDriver 2.33Windows XP (internet connection via proxy server)

发现我的问题?


  • 打开控制面板

  • 网络选项

  • 连接

  • LAN配置

  • 在此页面上,您可能会看到代理服务器的详细信息,并带有一个复选框:不要为本地地址使用代理服务器。
    此复选框可能已经选中(因为不使用代理的本地地址是有意义的)。
    不幸的是,Selenium WebDriver似乎忽略这个复选框,它的价值。
    选中或取消选中,它会检测您的代理服务器并将其应用于所有网址(或至少是在我的情况下它是这样做的)。

  • 高级按钮,并在例外框中手动输入127.0.0.1。

  • 保存更改。

  • - 在web驱动程序中运行测试,希望您不会再看到引用以下内容的错误消息:* self.session_id = response ['sessionId'] *

  • 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']*

在找到这个解决方案之前(借助一个经验丰富的工程师)
..用于设置/更改/绕过代理。没有得到我正在寻找的结果。

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.

我也看了这个:

..但它说的是一个较旧版本的webdriver,并建议删除所有的代理设置系统范围,这是绝对不起步的(就我而言)。

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

这篇关于为什么Selenium的响应没有sessionId?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 14:51