运行操作
运行python 脚本
错误日志
[HTTP] --> POST /wd/hub/session/0fc42238-dd32-4c85-b4d7-c08920ef4cc3/element
[HTTP] {"using":"xpath","value":"com.xueqiu.android:id/action_close"}
[debug] [W3C (0fc42238)] Calling AppiumDriver.findElement() with args: **["xpath","com.xueqiu.android:id/action_close","0fc42238-dd32-4c85-b4d7-c08920ef4cc3"]**
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 10000 ms for condition
[debug] [WD Proxy] Matched '/element' to command name 'findElement'
[debug] [WD Proxy] Proxying [POST /element] to [POST http://localhost:8209/wd/hub/session/c8198f76-0603-4a26-8183-853c5064d3a5/element] with body: {"strategy":"xpath","selector":"com.xueqiu.android:id/action_close","context":"","multiple":false}
[WD Proxy] Got an unexpected response with status 500: {"sessionId":"c8198f76-0603-4a26-8183-853c5064d3a5","value":{"error":"unknown error","message":"java.lang.IllegalArgumentException: Namespace with prefix 'com.xueqiu.android' has not been declared.","stacktrace":"io.appium.uiautomator2.common.exceptions.UiAutomator2Exception: java.lang.IllegalArgumentException: Namespace with prefix 'com.xueqiu.android' has not been declared.\n\tat io.appium.uiautomator2.core.AccessibilityNodeInfoDumper.findNodes(AccessibilityNodeInfoDumper.java:237)\n\tat io.appium.uiautomator2.utils.ElementLocationHelpers.getXPathNodeMatch(ElementLocationHelpers.java:86)\n\tat io.appium.uiautomator2.handler.FindElement.findElement(FindElement.java:100)\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:72)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(Appiu...
[debug] [W3C] Matched W3C error code 'unknown error' to UnknownError
问题分析
关键错误日志提示:不合法的参数异常,前缀是’com.xueqiu.android 的命名空间未定义,见下文;
这句话其实说的selector 中的com.xueqiu.android 前缀未定义;xpath表达式的前缀一般都是”//*“ 发现xpath表达式中写的是id 的表达式
{“strategy”:“xpath”,“selector”:“com.xueqiu.android:id/action_close”,“context”:"",“multiple”:false}
{"sessionId":"c8198f76-0603-4a26-8183-853c5064d3a5","value":{"error":"unknown error","message":"java.lang.IllegalArgumentException: Namespace with prefix 'com.xueqiu.android' has not been declared."
解决方案
把xpath 修改为id