driver.getContextHandles() does not work on appium1.5.3 version (1.4.13 version everything works as expected)

Hi All
Could you help me view a error happen on my environment

  • simulator with iOS 9.2 and Appium 1.5.3
  • My code
Set<?> contextHandles = driver.getContextHandles();
        String firstContextView = (String) contextHandles.toArray()[0];
        String lastestContextView = (String) contextHandles.toArray()[contextHandles.size() - 1];
        driver.context(lastestContextView);
        email.sendKeys(userName);
        pass.sendKeys(passWord);
        login.click();

And below is error log

[debug] [UIAuto] Socket data received (83 bytes)
[debug] [UIAuto] Got result from instruments: {"status":0,"value":{"origin":{"x":36,"y":235},"size":{"width":248,"height":36}}}
[debug] [UIAuto] Sending command to instruments: target.touch([{"touch":[{"x":160,"y":253}],"time":0.2},{"touch":[{"x":160,"y":253}],"time":0.7}])
[debug] [Instruments] [INST] 2016-06-09 10:42:42 +0000 Debug: Got new command 15 from instruments: target.touch([{"touch":[{"x":160,"y":253}],"time":0.2},{"touch":[{"x":160,"y":253}],"time":0.7}])
[debug] [Instruments] [INST] 2016-06-09 10:42:42 +0000 Debug: evaluating target.touch([{"touch":[{"x":160,"y":253}],"time":0.2},{"touch":[{"x":160,"y":253}],"time":0.7}])
[debug] [Instruments] [INST] 2016-06-09 10:42:42 +0000 Debug: target.touch(__NSCFArray)
[debug] [Instruments] [INST] 2016-06-09 10:42:42 +0000 Debug: evaluation finished
[debug] [Instruments] [INST] 2016-06-09 10:42:42 +0000 Debug: responding with:
[debug] [Instruments] [INST] 2016-06-09 10:42:42 +0000 Debug: Running system command #16: /usr/local/Cellar/node/6.2.0/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-ios-driver/node_modules/appium-uiauto/build/lib/bin/command-proxy-client.js /var/folders/qn/cdm4l2jj21n81ytjyxpgk_44ynjphk/T/instruments_sock 2,{"status":0,"value":""}...
[debug] [UIAuto] Socket data received (25 bytes)
[debug] [UIAuto] Got result from instruments: {"status":0,"value":""}
[MJSONWP] Responding to client with driver.performTouch() result: null
[HTTP] <-- POST /wd/hub/session/dc4f25e2-0bc0-4218-8bc0-f76b637e0cbb/touch/perform 200 2712 ms - 76 
[HTTP] --> GET /wd/hub/session/dc4f25e2-0bc0-4218-8bc0-f76b637e0cbb/contexts {}
[MJSONWP] Calling AppiumDriver.getContexts() with args: ["dc4f25e2-0bc0-4218-8bc0-f...
[debug] [iOS] Executing iOS command 'getContexts'
[debug] [iOS] Getting list of available contexts
[debug] [iOS] Retrieving contexts and views
[debug] [iOS] Selecting by url: false 
[debug] [RemoteDebugger] useNewSafari --> false
[debug] [RemoteDebugger] Debugger socket connected to ::1:27753
[debug] [RemoteDebugger] Sending connection key request
[debug] [RemoteDebugger] Sending '_rpc_reportIdentifier:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRSimulatorBuildKey":"13C75","WIRSimulatorProductVersionKey":"9.2","WIRSimulatorNameKey":"iPhone"},"__selector":"_rpc_reportSetup:"}'
[debug] [RemoteDebugger] Received response from socket send: '["iPhone","13C75","9.2"]'
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationDictionaryKey":{"PID:1520":{"WIRApplicationIdentifierKey":"PID:1520","WIRIsApplicationProxyKey":false,"WIRApplicationNameKey":"QC 6.3.7","WIRApplicationBundleIdentifierKey":"com.abc.def","WIRIsApplicationActiveKey":1}}},"__selector":"_rpc_reportConnectedApplicationList:"}'
[debug] [RemoteDebugger] Connected to application
[debug] [RemoteDebugger] Sim name: iPhone
[debug] [RemoteDebugger] Sim build: 13C75
[debug] [RemoteDebugger] Sim platform version: 9.2
[debug] [RemoteDebugger] Selecting application
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #1 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:938","WIRIsApplicationProxyKey":true,"WIRApplicationNameKey":"SafariViewService","WIRApplicationBundleIdentifierKey":"com.apple.SafariViewService","WIRIsApplicationActiveKey":1,"WIRHostApplicationIdentifierKey":"PID:869"},"__selector":"_rpc_applicationConnected:"}'
[debug] [RemoteDebugger] We were notified we might have connected to the wrong app. Using id PID:938 instead of PID:869
[debug] [RemoteDebugger] Notified that a new application PID:938 has connected
[debug] [RemoteDebugger] Current applications available:
[debug] [RemoteDebugger] Application: 'PID:1520'
[debug] [RemoteDebugger]     id: '"PID:1520"'
[debug] [RemoteDebugger]     name: '"QC 6.3.7"'
[debug] [RemoteDebugger]     bundleId: '"com.abc.def"'
[debug] [RemoteDebugger]     isProxy: 'false'
[debug] [RemoteDebugger]     hostId: 'undefined'
[debug] [RemoteDebugger]     isActive: '1'
[debug] [RemoteDebugger] Application: 'PID:938'
[debug] [RemoteDebugger]     id: '"PID:938"'
[debug] [RemoteDebugger]     name: '"SafariViewService"'
[debug] [RemoteDebugger]     bundleId: '"com.apple.SafariViewService"'
[debug] [RemoteDebugger]     isProxy: 'true'
[debug] [RemoteDebugger]     hostId: '"PID:869"'
[debug] [RemoteDebugger]     isActive: '1'
[debug] [RemoteDebugger]     pageDict: '{"promise":{"isFulfilled":false,"isRejected":false}}'
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1579","WIRIsApplicationProxyKey":true,"WIRApplicationNameKey":"","WIRApplicationBundleIdentifierKey":"com.apple.WebKit.WebContent","WIRIsApplicationActiveKey":1,"WIRHostApplicationIdentifierKey":"PID:938"},"__selector":"_rpc_applicationConnected:"}'
[debug] [RemoteDebugger] We were notified we might have connected to the wrong app. Using id PID:1579 instead of PID:938
[debug] [RemoteDebugger] Notified that a new application PID:1579 has connected
[debug] [RemoteDebugger] Current applications available:
[debug] [RemoteDebugger] Application: 'PID:1520'
[debug] [RemoteDebugger]     id: '"PID:1520"'
[debug] [RemoteDebugger]     name: '"QC 6.3.7"'
[debug] [RemoteDebugger]     bundleId: '"com.abc.def"'
[debug] [RemoteDebugger]     isProxy: 'false'
[debug] [RemoteDebugger]     hostId: 'undefined'
[debug] [RemoteDebugger]     isActive: '1'
[debug] [RemoteDebugger] Application: 'PID:938'
[debug] [RemoteDebugger]     id: '"PID:938"'
[debug] [RemoteDebugger]     name: '"SafariViewService"'
[debug] [RemoteDebugger]     bundleId: '"com.apple.SafariViewService"'
[debug] [RemoteDebugger]     isProxy: 'true'
[debug] [RemoteDebugger]     hostId: '"PID:869"'
[debug] [RemoteDebugger]     isActive: '1'
[debug] [RemoteDebugger]     pageDict: '{"promise":{"isFulfilled":false,"isRejected":false}}'
[debug] [RemoteDebugger] Application: 'PID:1579'
[debug] [RemoteDebugger]     id: '"PID:1579"'
[debug] [RemoteDebugger]     name: '""'
[debug] [RemoteDebugger]     bundleId: '"com.apple.WebKit.WebContent"'
[debug] [RemoteDebugger]     isProxy: 'true'
[debug] [RemoteDebugger]     hostId: '"PID:938"'
[debug] [RemoteDebugger]     isActive: '1'
[debug] [RemoteDebugger]     pageDict: '{"promise":{"isFulfilled":false,"isRejected":false}}'
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #2 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #3 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #4 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #5 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #6 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #7 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #8 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #9 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #10 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #11 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #12 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #13 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #14 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #15 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #16 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #17 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #18 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #19 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[debug] [RemoteDebugger] Found app id key 'PID:1520' for bundle 'com.abc.def'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:1520
[debug] [RemoteDebugger] Selecting app PID:1520 (try #20 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1520","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID:1520",{}]'
[debug] [RemoteDebugger] Page changed: {}
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Retrying connection
[RemoteDebugger] Error: Could not connect to a valid app after 20 tries.
    at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
    at RemoteDebugger.selectApp$ (lib/remote-debugger.js:216:11)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
 Error: Could not connect to a valid app after 20 tries.
    at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
    at RemoteDebugger.selectApp$ (lib/remote-debugger.js:216:11)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[MJSONWP] Encountered internal error running command: Error: Could not connect to a valid app after 20 tries.
    at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
    at RemoteDebugger.selectApp$ (lib/remote-debugger.js:216:11)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[HTTP] <-- GET /wd/hub/session/dc4f25e2-0bc0-4218-8bc0-f76b637e0cbb/contexts 500 146 ms - 219 
[HTTP] --> GET /wd/hub/session/dc4f25e2-0bc0-4218-8bc0-f76b637e0cbb/screenshot {}
[MJSONWP] Calling AppiumDriver.getScreenshot() with args: ["dc4f25e2-0bc0-4218-8bc0-f...
[debug] [iOS] Executing iOS command 'getScreenshot'
[debug] [iOS] Taking screenshot: '/var/folders/qn/cdm4l2jj21n81ytjyxpgk_44ynjphk/T/appium-instruments/Run 1/screenshote3163d19-ec80-491b-b9d7-b344670df834.png'
[debug] [UIAuto] Sending command to instruments: au.capture('screenshote3163d19-ec80-491b-b9d7-b344670df834')
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:938","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received page change notice for app PID:938 but listening for PID:1520. Ignoring.
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:1579","WIRListingKey":{"1":{"WIRTitleKey":"Xác nhận","WIRTypeKey":"WIRTypeWeb","WIRURLKey":"https://m.facebook.com/v2.5/dialog/oauth?client_id=461638860536540&default_audience=friends&display=touch&e2e=%7B%22init%22:1342.656828685%7D&fbapp_pres=0&redirect_uri=fb461638860536540://authorize/&response_type=token,signed_request&return_scopes=true&scope=user_photos,user_status,public_profile,email,user_friends,user_videos,user_posts&sdk=ios&sdk_version=4.7.1&state=%7B%22challenge%22:%228xTT1CL%252BYxzpjNahhz2qX3U8WCM%253D%22,%220_auth_logger_id%22:%2239BC77E8-A73E-464C-AFBC-A97E015CB702%22,%22com.facebook.sdk_client_state%22:true,%223_method%22:%22sfvc_auth%22%7D&sfvc=1","WIRPageIdentifierKey":1}}},"__selector":"_rpc_applicationSentListing:"}'

Thanks,
Ali

No everyone help me?

Hi All
I really met the issue. Could you please help me

FAILED: loginFace
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not connect to a valid app after 20 tries. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 118 milliseconds
Build info: version: ‘2.53.1’, revision: ‘a36b8b1cd5757287168e54b817830adce9b0158d’, time: ‘2016-06-30 19:26:09’
System info: host: ‘mbp-0033.local’, ip: ‘172.16.50.24’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.11.3’, java.version: ‘1.7.0_79’
Session ID: 42cb1b2b-5094-429f-bbc1-0f828c04d5fc
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities [{platform=MAC, app=/Users/tom.tran/git/myApp-QC.app, javascriptEnabled=true, browserName=iPhone, commandTtimeout=500, networkConnectionEnabled=false, desired={app=/Users/tom.tran/git/myApp-QC.app, platformVersion=9.2, platform=MAC, deviceName=iPhone 5s, platformName=iOS, browserName=iPhone, nativeInstrumentsLib=true, commandTtimeout=500, noReset=true, version=}, locationContextEnabled=false, noReset=true, version=, platformVersion=9.2, databaseEnabled=false, platformName=iOS, deviceName=iPhone 5s, nativeInstrumentsLib=true, webStorageEnabled=false, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:590)
at appium.app.test.TestLoginFaceAppium153.loginFaceBook(TestLoginFaceAppium153.java:82)

Thanks,

I have the same issue with Appium 1.6

I am clicking on a button in my app that redirects me to a website.
Then I am calling Set text = driver.getContextHandles();
to switch to the new context but the following error occurs:
An unknown server-side error occurred while processing the command. Original error: Could not connect to a valid app after 20 tries.

[debug] [MJSONWP] Calling AppiumDriver.getContexts() with args: [“0290c899-1e12-4251-bdbb-0485e6c51214”]
[debug] [iOS] Executing iOS command ‘getContexts’
[debug] [iOS] Getting list of available contexts
[debug] [iOS] Retrieving contexts and views
[debug] [iOS] Selecting by url: false

[debug] [RemoteDebugger] Received response from socket send: ‘[“PID:85604”,{}]’
[debug] [RemoteDebugger] Received page change notice for app ‘PID:85604’ but listening for ‘null’. Ignoring.
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Error checking application: ‘Error: Empty page dictionary received’. Retrying connection
[debug] [RemoteDebugger] Found app id key ‘PID:85604’ for bundle ‘at.xxx.xxxx’
[debug] [RemoteDebugger] Trying out the possible app ids: PID:85604
[debug] [RemoteDebugger] Selecting app PID:85604 (try #20 of 20)
[debug] [RemoteDebugger] Sending ‘_rpc_forwardGetListing:’ message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRApplicationIdentifierKey”:“PID:85604”,“WIRListingKey”:{}},"__selector":"_rpc_applicationSentListing:"}’

I installed the ios-webkit-debug-proxy but it didn’t change anything.
Have anyone a hint for me?

try it it might help you
Set contextNames = ((AppiumDriver) driver).getContextHandles();
for (String contextName : contextNames) {
System.out.println(“FIRST” + contextNames);
((AppiumDriver) driver).context(contextName);
//System.out.println("second "+ contextName.contains());
}

hey, thanks for your answer!

It’s the same code I already have:

Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
	System.out.println(contextName);
	 if (contextName.contains("WEBVIEW")){
	    driver.context(contextName);
	 }
 }

I am running Appium 1.6 with java-client 4.1.2 XCode 7.3.1 on a simulator
Safari Web Inspector is activated in the simulator and in the desktop version.

[debug] [MJSONWP] Calling AppiumDriver.getContexts() with args: [“9f3ad43a-6c73-42ec-82b4-1b822bd57283”]
[debug] [iOS] Executing iOS command ‘getContexts’
[debug] [iOS] Getting list of available contexts
[debug] [iOS] Retrieving contexts and views
[debug] [iOS] Selecting by url: false
[debug] [RemoteDebugger] useNewSafari --> false
[debug] [RemoteDebugger] Debugger socket connected to ::1:27753
[debug] [RemoteDebugger] Sending connection key request
[debug] [RemoteDebugger] Sending ‘_rpc_reportIdentifier:’ message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRSimulatorBuildKey”:“13E230”,“WIRSimulatorProductVersionKey”:“9.3”,“WIRSimulatorNameKey”:“iPhone”},"__selector":"_rpc_reportSetup:"}’
[debug] [RemoteDebugger] Received response from socket send: ‘[“iPhone”,“13E230”,“9.3”]’
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRApplicationDictionaryKey”:{“PID:62490”:{“WIRApplicationIdentifierKey”:“PID:62490”,“WIRIsApplicationProxyKey”:false,“WIRApplicationNameKey”:“ÖBB”,“WIRApplicationBundleIdentifierKey”:“at.xxx.xxx”,“WIRIsApplicationActiveKey”:1}}},"__selector":"_rpc_reportConnectedApplicationList:"}’
[debug] [RemoteDebugger] Connected to application
[debug] [RemoteDebugger] Sim name: iPhone
[debug] [RemoteDebugger] Sim build: 13E230
[debug] [RemoteDebugger] Sim platform version: 9.3
[debug] [RemoteDebugger] Selecting application
[debug] [RemoteDebugger] Found app id key ‘PID:62490’ for bundle ‘at.xxx.xxx’
[debug] [RemoteDebugger] Trying out the possible app ids: PID:62490
[debug] [RemoteDebugger] Selecting app PID:62490 (try #1 of 20)
[debug] [RemoteDebugger] Sending ‘_rpc_forwardGetListing:’ message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRApplicationIdentifierKey”:“PID:62490”,“WIRListingKey”:{}},"__selector":"_rpc_applicationSentListing:"}’
[debug] [RemoteDebugger] Received response from socket send: ‘[“PID:62490”,{}]’
[debug] [RemoteDebugger] Received page change notice for app ‘PID:62490’ but listening for ‘null’. Ignoring.
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Error checking application: ‘Error: Empty page dictionary received’. Retrying connection
[debug] [RemoteDebugger] Found app id key ‘PID:62490’ for bundle ‘at.xxx.xxx’
[debug] [RemoteDebugger] Trying out the possible app ids: PID:62490
[debug] [RemoteDebugger] Selecting app PID:62490 (try #2 of 20)
[debug] [RemoteDebugger] Sending ‘_rpc_forwardGetListing:’ message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRApplicationIdentifierKey”:“PID:62490”,“WIRListingKey”:{}},"__selector":"_rpc_applicationSentListing:"}’
[debug] [RemoteDebugger] Received response from socket send: ‘[“PID:62490”,{}]’
[debug] [RemoteDebugger] Received page change notice for app ‘PID:62490’ but listening for ‘null’. Ignoring.
[debug] [RemoteDebugger] Empty page dictionary received
[debug] [RemoteDebugger] Error checking application: ‘Error: Empty page dictionary received’. Retrying connection
[debug] [RemoteDebugger] Found app id key ‘PID:62490’ for bundle ‘at.xxx.xxx’
[debug] [RemoteDebugger] Trying out the possible app ids: PID:62490
.
.
.
20 tries…
.
.
.[RemoteDebugger] Error: Could not connect to a valid app after 20 tries.
at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
at RemoteDebugger.selectApp$ (lib/remote-debugger.js:252:6)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
Error: Could not connect to a valid app after 20 tries.
at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
at RemoteDebugger.selectApp$ (lib/remote-debugger.js:252:6)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[MJSONWP] Encountered internal error running command: Error: Could not connect to a valid app after 20 tries.
at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
at RemoteDebugger.selectApp$ (lib/remote-debugger.js:252:6)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[HTTP] <-- GET /wd/hub/session/9f3ad43a-6c73-42ec-82b4-1b822bd57283/contexts 500 215 ms - 219
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRApplicationIdentifierKey”:“PID:79683”,“WIRIsApplicationProxyKey”:true,“WIRApplicationNameKey”:"",“WIRApplicationBundleIdentifierKey”:“com.apple.WebKit.WebContent”,“WIRIsApplicationActiveKey”:1,“WIRHostApplicationIdentifierKey”:“PID:62490”},"__selector":"_rpc_applicationConnected:"}’
[debug] [RemoteDebugger] Notified that new application ‘PID:79683’ has connected
[debug] [RemoteDebugger] Current applications available:
[debug] [RemoteDebugger] Application: ‘PID:62490’
[debug] [RemoteDebugger] id: “PID:62490”
[debug] [RemoteDebugger] isProxy: false
[debug] [RemoteDebugger] name: “xxx”
[debug] [RemoteDebugger] bundleId: “at.xxx.xxx”
[debug] [RemoteDebugger] hostId: undefined
[debug] [RemoteDebugger] isActive: 1
[debug] [RemoteDebugger] isAutomationEnabled: false
[debug] [RemoteDebugger] pageDict: []
[debug] [RemoteDebugger] Application: ‘PID:79683’
[debug] [RemoteDebugger] id: “PID:79683”
[debug] [RemoteDebugger] isProxy: true
[debug] [RemoteDebugger] name: “”
[debug] [RemoteDebugger] bundleId: “com.apple.WebKit.WebContent”
[debug] [RemoteDebugger] hostId: “PID:62490”
[debug] [RemoteDebugger] isActive: 1
[debug] [RemoteDebugger] isAutomationEnabled: false
[debug] [RemoteDebugger] pageDict: “Waiting for data”
[debug] [RemoteDebugger] Found app id key ‘PID:62490’ for bundle ‘at.xxx.xxx’
[debug] [RemoteDebugger] Found separate bundleId ‘com.apple.WebKit.WebContent’ acting as proxy for ‘at.xxx.xxx’, with app id ‘PID:79683’
[debug] [RemoteDebugger] Using proxied app id ‘PID:79683’
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRApplicationIdentifierKey”:“PID:79683”,“WIRListingKey”:{“1”:{“WIRTitleKey”:"",“WIRTypeKey”:“WIRTypeWeb”,“WIRURLKey”:“about:blank”,“WIRPageIdentifierKey”:1}}},"__selector":"_rpc_applicationSentListing:"}’
[debug] [RemoteDebugger] Page changed: {“1”:{“WIRTitleKey”:"",“WIRTypeKey”:“WIRTypeWeb”,“WIRURLKey”:“about:blank”,“WIRPageIdentifierKey”:1}}
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRApplicationIdentifierKey”:“PID:79683”,“WIRListingKey”:{“1”:{“WIRTitleKey”:“Volksbank Internet-Banking -Demo - eps-Überweisung - Anmeldung”,“WIRTypeKey”:“WIRTypeWeb”,“WIRURLKey”:“https://www.banking.co.at/appl/ebp/so/login/eps.html?demo=true&resource=101",“WIRPageIdentifierKey”:1}}},"__selector":"_rpc_applicationSentListing:”}’
[debug] [RemoteDebugger] Page changed: {“1”:{“WIRTitleKey”:“Volksbank Internet-Banking -Demo - eps-Überweisung - Anmeldung”,“WIRTypeKey”:“WIRTypeWeb”,“WIRURLKey”:“https://www.banking.co.at/appl/ebp/so/login/eps.html?demo=true&resource=101","WIRPageIdentifierKey”:1}}
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRApplicationIdentifierKey”:“PID:62490”,“WIRListingKey”:{“19”:{“WIRPageIdentifierKey”:19,“WIRTitleKey”:“JSContext”,“WIRTypeKey”:“WIRTypeJavaScript”}}},"__selector":"_rpc_applicationSentListing:"}’
[debug] [RemoteDebugger] Received page change notice for app ‘PID:62490’ but listening for ‘PID:79683’. Ignoring.
[debug] [RemoteDebugger] Receiving data from remote debugger: ‘{"__argument":{“WIRApplicationIdentifierKey”:“PID:62490”,“WIRListingKey”:{}},"__selector":"_rpc_applicationSentListing:"}’
[debug] [RemoteDebugger] Received page change notice for app ‘PID:62490’ but listening for ‘PID:79683’. Ignoring.

I am a bit confused by the line
[debug] [RemoteDebugger] useNewSafari --> false

what does that mean? why is it false?
And then by:
[debug] [RemoteDebugger] Notified that new application ‘PID:79683’ has connected
[debug] [RemoteDebugger] Received page change notice for app ‘PID:39157’ but listening for ‘PID:53357’. Ignoring.

Is it possible, that the webview that is opening is recognised as a totally new app? And appium is confused and ignoring the “new” one keeps listening to the “old” native one because it thinks it is a new app and not just a webview? Or something like this

1 Like

I am also facing the same issue… Did you get any solution for this issue ??

That was a long time ago :smiley:

I can’t remember exactly. I guess I used an implicit wait to wait for the webview to load as a workaround.
But with an newer version of Appium (or appium java-client) the problem as resolved and everyting worked.

Acutally, now since Appim 1.7.0 I don’t need to switch context anymore! I don’t know if this is a bug, but I find the elements staying at the native context, or rather, I can’t find any useful element with the webview context anymore.