【问题标题】:Androiddriver Python Bindings httplibAndroiddriver Python 绑定 httplib
【发布时间】:2013-04-25 17:16:39
【问题描述】:

我能够在模拟器上成功设置 androiddriver,但我正在努力解决 httplib 错误。这是我在mac上设置android sdk后采取的步骤。

1.  ./adb devices, which returned emulator-5554
2. ./adb emulator-5554 -s forward tcp:8080 tcp:8080
3. visited http://localhost:8080/wd/hub/status in my browser and received a { status: 0 }
4. In the python shell (tried this on both python 2.7 & 2.6), I did:

>> from selenium import webdriver
>> from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
>> driver = webdriver.Remote("http://localhost:8080/wd/hub",     webdriver.DesiredCapabilities.ANDROID)
>> driver.get("http://www.google.com")

有时,当我设置驱动程序变量时,我会收到错误(如下),有时不会。 driver.get 命令也是如此。

堆栈跟踪如下:

  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: ''

还有其他人有解决这个问题的想法吗?

【问题讨论】:

  • 更新 - 我安装了旧版本的 android-server apk(之前使用的是 android-2.32.0)。
  • 使用 android-server-2.21.0.apk link 工作正常
  • 我整天都在努力让它发挥作用。我从来没有想过 apk 是问题所在。

标签: android python selenium-webdriver remotewebdriver


【解决方案1】:

正如您所说,这已在 android-server 的 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

请注意,在我从 2.3.2 APK 降级到 2.2.1 APK 之前,我仍然遇到 save_screenshotBadStatusLine 的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    相关资源
    最近更新 更多