新手区 appium 使用 find_element_by_android_uiautomator 定位出错

April · 2016年03月18日 · 最后由 江寒 回复于 2017年10月31日 · 1648 次阅读

学习 find_element_by_android_uiautomator 来定位,但是出错:
报错信息:

Error
Traceback (most recent call last):
  File "F:\autotest\app-yggdrasil\code\source\Keyword\AppTest\loginJinlu.py", line 42, in test_login
    self.driver.find_element_by_android_uiautomator("new UiSelector().content-desc(\"元素contentdesc\")")
  File "C:\Users\vip\AppData\Roaming\Python\Python27\site-packages\appium\webdriver\webdriver.py", line 110, in find_element_by_android_uiautomator
    return self.find_element(by=By.ANDROID_UIAUTOMATOR, value=uia_string)
  File "C:\Users\vip\AppData\Roaming\Python\Python27\site-packages\selenium\webdriver\remote\webdriver.py", line 712, in find_element
    {'using': by, 'value': value})['value']
  File "C:\Users\vip\AppData\Roaming\Python\Python27\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "C:\Users\vip\AppData\Roaming\Python\Python27\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
    raise wde
WebDriverException: Message: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.

代码:

self.driver.find_element_by_android_uiautomator("new UiSelector().content-desc(\"元素contentdesc\")")

元素信息:

appiumlog:

 info: Shutting down appium session
> info: [debug] Pressing the HOME button
> info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s b3413520 shell "input keyevent 3"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
> info: [debug] [BOOTSTRAP] [debug] Closed client connection
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
> info: [debug] [UIAUTOMATOR STDOUT] Time: 21.076
> info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> info: [debug] UiAutomator shut down normally
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"3f17452f-760b-4d8c-8421-b5c8606be9fd"}
> info: <-- DELETE /wd/hub/session/3f17452f-760b-4d8c-8421-b5c8606be9fd 200 750.192 ms - 76 {"status":0,"value":null,"sessionId":"3f17452f-760b-4d8c-8421-b5c8606be9fd"}

在 python 里面不能用这个方法定位吗?望赐教~~

共收到 5 条回复 时间 点赞

把 appium server log 附上来吧。

PS:为何要把 content-desc 的值打码。。。

#1 楼 @help33 重新编辑了,把 log 附上去了

UiSelector文档,没有.content-desc()方法

另外,你没有给出查找时对应的 log ,不确定的时候附上全部 log 就好了

#3 楼 @sanlengjingvv 好的,谢谢·

楼主,你的问题,解决了吗?我也遇到了

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册