2013-04-25 53 views
2

我成功地能够在模拟器上设置androiddriver,但我正在努力解决httplib错误。以下是在mac上设置android sdk后所执行的步骤。有些时候,当我设置驱动变量时,我会得到错误(下面),有时候不会。 driver.get命令也是如此。Androiddriver Python绑定httplib

堆栈跟踪低于:

File "<stdin>", line 1, in <module> 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 177, in get 
    self.execute(Command.GET, {'url': url}) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 163, in execute 
    response = self.command_executor.execute(driver_command, params) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 349, 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 396, in _request 
response = opener.open(request) 
    File  "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 394, in open 
    response = self._open(req, data) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 412, in _open 
'_open', req) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 372, in _call_chain 
    result = func(*args) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1199, in http_open 
    return self.do_open(httplib.HTTPConnection, req) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1170, in do_open 
    r = h.getresponse(buffering=True) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1027, in getresponse 
response.begin() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 407, in begin 
version, status, reason = self._read_status() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 371, in _read_status 
    raise BadStatusLine(line) 
httplib.BadStatusLine: '' 

别人也有一个解决的办法的想法?

+2

更新 - 我安装了旧版本的android服务器apk(正在使用android- 2.32.0之前)。 – qaduderino 2013-04-29 21:32:11

+2

使用android-server-2.21.0.apk [链接](https://code.google.com/p/selenium/downloads/detail?name=android-server-2.21.0.apk&can=2&q=)这是正常工作 – qaduderino 2013-04-29 21:39:05

+0

我一直在努力工作。我从来没有想到apk是这个问题。 – 2013-09-25 17:43:18

回答

0

正如你所说这是固定在android服务器的newer version。但是,对于那些无法更新的问题:其原因是由于驱动程序认为页面已过早加载到正在加载的实际页面。 Selenium从驱动程序收到一些HTTP头信息,状态行无效。例如,

而不是HTTP/1.0 200状态行是空白的(如上所述)。

我发现解决这个问题的一种方法是等待足够长的时间,在该时间段内页面被假定为已经加载,然后尝试建立连接。

我通常会得到这样的异常与这行代码:

android = webdriver.Remote(command_executor='http://127.0.0.1:8080/wd/hub', desired_capabilities=capabilities.ANDROID) 

因此,要解决,我只是改变了代码等到调用成功:

android = None 
while android is None: 
    try: 
     android = webdriver.Remote(command_executor='http://127.0.0.1:8080/wd/hub', desired_capabilities=capabilities.ANDROID) 
    except: 
     time.sleep(1) 
     pass 

请注意,我还有save_screenshotBadStatusLine的问题,直到我降级从2.3.2 APK到2.2.1 APK