2013-04-25 56 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