环境:

问题 1:

使用 driver.findElementByAccessibilityId("退出登录") 查找不到该元素,实际页面已经切到对应页面 且该按钮已经出现。请使用过 1.5.x 的同学分享一下经验,谢谢!

Appium Log:

2016-08-08 14:17:40:053 - info: [HTTP] --> POST /wd/hub/session/e7202c53-50b2-4981-9628-9ceaaccb9606/element {"using":"accessibility id","value":"退出登录"}
2016-08-08 14:17:40:053 - info: [MJSONWP] Calling AppiumDriver.findElement() with args: ["accessibility id","退出登录",...
2016-08-08 14:17:40:054 - info: [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2016-08-08 14:17:40:054 - info: [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2016-08-08 14:17:40:054 - info: [debug] [BaseDriver] Waiting up to 0 ms for condition
2016-08-08 14:17:40:055 - info: [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"accessibility id","selector":"退出登录","context":"","multiple":false}}
2016-08-08 14:17:40:062 - info: [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"accessibility id","selector":"退出登录","context":"","multiple":false}}
2016-08-08 14:17:40:066 - info: [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2016-08-08 14:17:40:067 - info: [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
2016-08-08 14:17:40:067 - info: [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '退出登录' using 'ACCESSIBILITY_ID' with the contextId: '' multiple: false
2016-08-08 14:17:40:067 - info: [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[DESCRIPTION=退出登录, INSTANCE=0]
2016-08-08 14:17:40:151 - info: [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
2016-08-08 14:17:40:151 - info: [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '退出登录' using 'ACCESSIBILITY_ID' with the contextId: '' multiple: false
2016-08-08 14:17:40:152 - info: [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[DESCRIPTION=退出登录, INSTANCE=0]
2016-08-08 14:17:40:253 - info: [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}

问题 2:

Hybrid 应用,切换到 WEBVIEW 时遇到问题,能正常打印出 contexts,但切换到 WEBVIEW 时抛异常 no such session。

public void toWeb() {
    List<String> handleList = new ArrayList<String>();
    Set<String> set = driver.getContextHandles();
    Iterator<String> it = set.iterator();
    while (it.hasNext()) {
        handleList.add(it.next());
    }
    try {
        driver.context(handleList.get(1));
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}

运行异常信息:

no such session
  (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 3.10.0-327.22.2.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 21 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'qianchang-PC', ip: '127.0.0.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_80'
*** Element info: {Using=class name, value=UBI-line-1}
Session ID: dc4862f3-8fd3-4bb4-8db3-84859b272ec1
Driver info: com.test.driver.TestDriver
Capabilities [{platform=LINUX, app=/JenkinsWorkSpace/workspace/Kartor_Android_UBI/apps/kartor_debug_4.9.0.0080.apk, javascriptEnabled=true, appActivity=cn.cst.iov.app.LaunchActivity, browserName=, networkConnectionEnabled=true, noSign=true, desired={newCommandTimeout=300, app=/JenkinsWorkSpace/workspace/Kartor_Android_UBI/apps/kartor_debug_4.9.0.0080.apk, platformName=Android, deviceName=Android, browserName=, noSign=true, unicodeKeyboard=true, resetKeyboard=true, noReset=true}, locationContextEnabled=false, appPackage=cn.cstonline.kartor3, deviceUDID=QMSDU15A24012345, noReset=true, newCommandTimeout=300, platformVersion=5.1.1, databaseEnabled=false, appWaitPackage=cn.cstonline.kartor3, platformName=Android, deviceName=QMSDU15A24012345, appWaitActivity=cn.cst.iov.app.LaunchActivity, webStorageEnabled=false, unicodeKeyboard=true, resetKeyboard=true, warnings={}, takesScreenshot=true}]

Appium Log:

2016-08-08 20:33:28:768 - info: [HTTP] --> GET /wd/hub/session/dc4862f3-8fd3-4bb4-8db3-84859b272ec1/contexts {}
2016-08-08 20:33:28:770 - info: [MJSONWP] Calling AppiumDriver.getContexts() with args: ["dc4862f3-8fd3-4bb4-8db3-8...
2016-08-08 20:33:28:773 - info: [debug] [AndroidDriver] Getting a list of available webviews
2016-08-08 20:33:28:774 - info: [debug] [ADB] Getting connected devices...
2016-08-08 20:33:28:796 - info: [debug] [ADB] 1 device(s) connected
2016-08-08 20:33:28:797 - info: [debug] [ADB] Running /usr/local/androidsdk/platform-tools/adb with args: ["-P",5037,"-s","QMSDU15A24012345","shell","cat","/proc/net/unix"]
2016-08-08 20:33:28:867 - info: [debug] [AndroidDriver] WEBVIEW_11385 mapped to pid 11385
2016-08-08 20:33:28:867 - info: [debug] [AndroidDriver] Getting process name for webview
2016-08-08 20:33:28:869 - info: [debug] [ADB] Getting connected devices...
2016-08-08 20:33:28:890 - info: [debug] [ADB] 1 device(s) connected
2016-08-08 20:33:28:890 - info: [debug] [ADB] Running /usr/local/androidsdk/platform-tools/adb with args: ["-P",5037,"-s","QMSDU15A24012345","shell","ps"]
2016-08-08 20:33:29:026 - info: [debug] [AndroidDriver] Parsed pid: 11385 pkg: cn.cstonline.kartor3!
2016-08-08 20:33:29:026 - info: [debug] [AndroidDriver] from: u0_a158,11385,390,1923008,173416,ffffffff,00000000,R,cn.cstonline.kartor3
2016-08-08 20:33:29:027 - info: [debug] [AndroidDriver] returning process name: cn.cstonline.kartor3
2016-08-08 20:33:29:028 - info: [debug] [AndroidDriver] Found webviews: ["WEBVIEW_cn.cstonline.kartor3"]
2016-08-08 20:33:29:028 - info: [debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_cn.cstonline.kartor3"]
2016-08-08 20:33:29:031 - info: [MJSONWP] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_cn.c...
2016-08-08 20:33:29:036 - info: [HTTP] <-- GET /wd/hub/session/dc4862f3-8fd3-4bb4-8db3-84859b272ec1/contexts 200 265 ms - 117 
2016-08-08 20:33:29:041 - info: [HTTP] --> POST /wd/hub/session/dc4862f3-8fd3-4bb4-8db3-84859b272ec1/context {"name":"WEBVIEW_cn.cstonline.kartor3"}
2016-08-08 20:33:29:042 - info: [MJSONWP] Calling AppiumDriver.setContext() with args: ["WEBVIEW_cn.cstonline.kart...
2016-08-08 20:33:29:045 - info: [debug] [AndroidDriver] Getting a list of available webviews
2016-08-08 20:33:29:045 - info: [debug] [ADB] Getting connected devices...
2016-08-08 20:33:29:066 - info: [debug] [ADB] 1 device(s) connected
2016-08-08 20:33:29:067 - info: [debug] [ADB] Running /usr/local/androidsdk/platform-tools/adb with args: ["-P",5037,"-s","QMSDU15A24012345","shell","cat","/proc/net/unix"]
2016-08-08 20:33:29:132 - info: [debug] [AndroidDriver] WEBVIEW_11385 mapped to pid 11385
2016-08-08 20:33:29:133 - info: [debug] [AndroidDriver] Getting process name for webview
2016-08-08 20:33:29:134 - info: [debug] [ADB] Getting connected devices...
2016-08-08 20:33:29:153 - info: [debug] [ADB] 1 device(s) connected
2016-08-08 20:33:29:154 - info: [debug] [ADB] Running /usr/local/androidsdk/platform-tools/adb with args: ["-P",5037,"-s","QMSDU15A24012345","shell","ps"]
2016-08-08 20:33:29:257 - info: [debug] [AndroidDriver] Parsed pid: 11385 pkg: cn.cstonline.kartor3!
2016-08-08 20:33:29:257 - info: [debug] [AndroidDriver] from: u0_a158,11385,390,1923008,173416,ffffffff,00000000,S,cn.cstonline.kartor3
2016-08-08 20:33:29:262 - info: [debug] [AndroidDriver] returning process name: cn.cstonline.kartor3
2016-08-08 20:33:29:263 - info: [debug] [AndroidDriver] Found webviews: ["WEBVIEW_cn.cstonline.kartor3"]
2016-08-08 20:33:29:264 - info: [debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_cn.cstonline.kartor3"]
2016-08-08 20:33:29:265 - info: [debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_cn.cstonline.kartor3'
2016-08-08 20:33:29:269 - info: [debug] [Chromedriver] Changed state to 'starting'
2016-08-08 20:33:29:296 - info: [Chromedriver] Set chromedriver binary as: /usr/lib/node_modules/.appium_npminstall/node_modules/.appium-chromedriver@2.9.2/chromedriver/linux/chromedriver_64
2016-08-08 20:33:29:298 - info: [Chromedriver] Killing any old chromedrivers, running: pkill -15 -f "/usr/lib/node_modules/.appium_npminstall/node_modules/.appium-chromedriver@2.9.2/chromedriver/linux/chromedriver_64.*--port=9515"
2016-08-08 20:33:29:388 - info: [Chromedriver] No old chromedrivers seemed to exist
2016-08-08 20:33:29:390 - info: [Chromedriver] Spawning chromedriver with: /usr/lib/node_modules/.appium_npminstall/node_modules/.appium-chromedriver@2.9.2/chromedriver/linux/chromedriver_64 --url-base=wd/hub --port=9515 --adb-port=5037
2016-08-08 20:33:29:414 - info: [Chromedriver] [STDOUT] Starting ChromeDriver 2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a) on port 9515
Only local connections are allowed.
2016-08-08 20:33:29:418 - info: [JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
2016-08-08 20:33:29:448 - info: [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"stat...
2016-08-08 20:33:29:450 - info: [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"ch...
2016-08-08 20:33:30:526 - info: [JSONWP Proxy] Got response with status 200: {"sessionId":"6e2bbbd8e02b8...
2016-08-08 20:33:30:527 - info: [debug] [Chromedriver] Changed state to 'online'
2016-08-08 20:33:30:528 - info: [MJSONWP] Responding to client with driver.setContext() result: null


↙↙↙阅读原文可查看相关链接,并与作者交流