Quantcast
Channel: 软件测试 –笑遍世界
Viewing all articles
Browse latest Browse all 50

Selenium 2.38.2 和 PhantomJS 1.9.2 一起使用的一个Bug

$
0
0

首先说明,这个Bug已经在这两天发布的Selenium 2.38.4版本中被修复了,如果使用的2.38.1、2.38.2等版本的Selenium,则依然会遇到。
这个Bug,在确定原因之前,折磨了我一两天时间;所以还是记录一下。

描述:在python 2.7环境中,使用Selenium 2.38.2 和 PhantomJS 1.9.2 写一个简单的打开某个网页的脚本,如我前面一篇文章中讲的那样:(使用Selenium和PhantomJS解析带JS的网页),就会遇到Bug,根本就不能打开网页。返回的错误信息为“httplib.BadStatusLine: ””或“socket.error: [Errno 54] Connection reset by peer”。 PS:我发现在Python 2.6环境中,同样的Selenium 2.38.2 和 PhantomJS 1.9.2 却一般不会遇到这个问题(这个问题没深究了)。

具体的描述和讨论,见Selenium项目主页上的这个issue: http://code.google.com/p/selenium/issues/detail?id=6690
具体Fix这个bug的代码在:https://github.com/SeleniumHQ/selenium/commit/a1df581908b7a0165dd232151647a23b5d6b4800

解决方案:(很简单 ^_^)
1. 回退Selenium版本到2.37.2;

1
2
sudo pip uninstall selenium 
sudo pip install selenium==2.37.2

2. 升级Selenium版本到2.38.4.

1
 sudo pip install -U selenium


可能遇到的报错信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
jay@jay-linux:~/workspace/python_test$ python try_phantomjs.py
Traceback (most recent call last):
  File "try_phantomjs.py", line 17, in <module>
    driver.get("http://www.ip.cn/125.95.26.81")
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 176, in get
    self.execute(Command.GET, {'url': url})
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 162, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 350, in execute
    return self._request(url, method=command_info[0], data=data)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 382, in _request
    resp = self._conn.getresponse()
  File "/usr/lib/python2.7/httplib.py", line 1030, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 407, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 371, in _read_status
    raise BadStatusLine(line)
httplib.BadStatusLine: ''

也偶尔是这样的报错信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
jay@Jay-Air:~/workspace/python_study/dp/qa/2013/12 $python try_phantomjs.py
Traceback (most recent call last):
  File "try_phantomjs.py", line 17, in <module>
    driver.get("http://dianping.com/")
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 176, in get
    self.execute(Command.GET, {'url': url})
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 162, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 355, in execute
    return self._request(url, method=command_info[0], data=data)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 384, in _request
    resp = self._conn.getresponse()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1045, in getresponse
    response.begin()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 409, in begin
    version, status, reason = self._read_status()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 365, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
socket.error: [Errno 54] Connection reset by peer

Original article: Selenium 2.38.2 和 PhantomJS 1.9.2 一起使用的一个Bug

©2015 笑遍世界. All Rights Reserved.


Viewing all articles
Browse latest Browse all 50