Appium throws noSuchContextExcpetion even though it exists

I have this code:

    public boolean fluentWaitChangeContext(String context, int timeout) {
        Wait wait = new FluentWait(driver)
                .withTimeout(timeout, TimeUnit.SECONDS)
                .pollingEvery(5, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class, NoSuchContextException.class);

//        final WebElement element1;
        boolean isFound = false;
        try {
            wait.until(input -> {
                if (driver.getContextHandles().size() == 2) {
                    driver.context("WEBVIEW_com.ridewith");
//                    element1 = driver.findElement(By.cssSelector("#braintree > iframe"));
//                    element.findElement(By.cssSelector(""));
                    return true;
                }
                return null;
            });
        } catch (org.openqa.selenium.TimeoutException exc) {

        }
        return isFound;
    }

I see with debug that

driver.getContextHandles() returns

"NATIVE_APP" and "WEBVIEW_com.ridewith"

and yet my code throws most of the time noSuchContextExcpetion

how can I fix this?

my android-appium server log:

info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_com.ridewith"],"sessionId":"fc48a3a2-d3a9-4586-95f1-f11d15396e16"}
info: <-- GET /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/contexts 200 262.002 ms - 109 {"status":0,"value":["NATIVE_APP","WEBVIEW_com.ridewith"],"sessionId":"fc48a3a2-d3a9-4586-95f1-f11d15396e16"}
info: --> POST /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/context {"name":"WEBVIEW_com.ridewith"}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "cat /proc/net/unix"
info: [debug] WEBVIEW_672 mapped to pid 672
info: [debug] Getting process name for webview
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "ps"
info: [debug] Parsed pid: 672 pkg: undefined
info: [debug] from: u0_a314,672,1746,1523268,234956,00000000,R,com.ridewith
info: [debug] returning process name: undefined
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
info: [debug] ["WEBVIEW_undefined"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_undefined
info: [debug] Responding to client with error: {"status":35,"value":{"message":"No such context found.","origValue":"Context 'WEBVIEW_com.ridewith' does not exist"},"sessionId":"fc48a3a2-d3a9-4586-95f1-f11d15396e16"}
info: <-- POST /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/context 500 212.540 ms - 169
info: --> GET /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/contexts {}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "cat /proc/net/unix"
info: [debug] WEBVIEW_672 mapped to pid 672
info: [debug] Getting process name for webview
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "ps"
info: [debug] Parsed pid: 672 pkg: com.ridewith
info: [debug] from: u0_a314,672,1746,1523268,231140,SyS_epoll_,00000000,S,com.ridewith
info: [debug] returning process name: com.ridewith
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_undefined
info: [debug] ["WEBVIEW_com.ridewith"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_com.ridewith"],"sessionId":"fc48a3a2-d3a9-4586-95f1-f11d15396e16"}
info: <-- GET /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/contexts 200 257.041 ms - 109 {"status":0,"value":["NATIVE_APP","WEBVIEW_com.ridewith"],"sessionId":"fc48a3a2-d3a9-4586-95f1-f11d15396e16"}
info: --> GET /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/contexts {}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "cat /proc/net/unix"
info: [debug] WEBVIEW_672 mapped to pid 672
info: [debug] Getting process name for webview
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "ps"
info: [debug] Parsed pid: 672 pkg: com.ridewith
info: [debug] from: u0_a314,672,1746,1523268,231404,SyS_epoll_,00000000,S,com.ridewith
info: [debug] returning process name: com.ridewith
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
info: [debug] ["WEBVIEW_com.ridewith"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_com.ridewith"],"sessionId":"fc48a3a2-d3a9-4586-95f1-f11d15396e16"}
info: <-- GET /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/contexts 200 306.958 ms - 109 {"status":0,"value":["NATIVE_APP","WEBVIEW_com.ridewith"],"sessionId":"fc48a3a2-d3a9-4586-95f1-f11d15396e16"}
info: --> GET /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/contexts {}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "cat /proc/net/unix"
info: [debug] WEBVIEW_672 mapped to pid 672
info: [debug] Getting process name for webview
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "ps"
info: [debug] Parsed pid: 672 pkg: com.ridewith
info: [debug] from: u0_a314,672,1746,1523268,231404,SyS_epoll_,00000000,S,com.ridewith
info: [debug] returning process name: com.ridewith
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
info: [debug] ["WEBVIEW_com.ridewith"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_com.ridewith"],"sessionId":"fc48a3a2-d3a9-4586-95f1-f11d15396e16"}
info: <-- GET /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/contexts 200 203.257 ms - 109 {"status":0,"value":["NATIVE_APP","WEBVIEW_com.ridewith"],"sessionId":"fc48a3a2-d3a9-4586-95f1-f11d15396e16"}
info: --> POST /wd/hub/session/fc48a3a2-d3a9-4586-95f1-f11d15396e16/context {"name":"WEBVIEW_com.ridewith"}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "cat /proc/net/unix"
info: [debug] WEBVIEW_672 mapped to pid 672
info: [debug] Getting process name for webview
info: [debug] executing cmd: /Users/eladb/MyWorkspace/sdk/platform-tools/adb -s ZX1G425VDZ shell "ps"
info: [debug] Parsed pid: 672 pkg: com.ridewith
info: [debug] from: u0_a314,672,1746,1523268,232196,SyS_epoll_,00000000,S,com.ridewith
info: [debug] returning process name: com.ridewith
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
info: [debug] ["WEBVIEW_com.ridewith"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.ridewith
info: [debug] Connecting to chrome-backed webview
info: Chromedriver: Changed state to 'starting'
info: Chromedriver: Set chromedriver binary as: /Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver
info: Chromedriver: Killing any old chromedrivers, running: ps -ef | grep /Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver | grep -v grep |grep -e '--port=9515\(\s.*\)\?$' | awk '{ print $2 }' | xargs kill -15
info: Chromedriver: Successfully cleaned up old chromedrivers
info: Chromedriver: Spawning chromedriver with: /Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver --url-base=wd/hub --port=9515
info: Chromedriver: [STDOUT] Starting ChromeDriver 2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281) on port 9515
Only local connections are allowed.
info: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Mac OS X\",\"version\":\"10.11.2\"}}}"
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.ridewith","androidUseRunningApp":true,"androidDeviceSerial":"ZX1G425VDZ"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"416e06c145f7cfda339ba0c0e72e7164","status":13,"value":{"message":"unknown error: Device ZX1G425VDZ is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.ridewith","androidUseRunningApp":true,"androidDeviceSerial":"ZX1G425VDZ"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"66fa77c18596c81554b0d43ff814cc17","status":13,"value":{"message":"unknown error: Device ZX1G425VDZ is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.ridewith","androidUseRunningApp":true,"androidDeviceSerial":"ZX1G425VDZ"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"d853b5942c7cd0160af27bceeea5d628","status":13,"value":{"message":"unknown error: Device ZX1G425VDZ is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.ridewith","androidUseRunningApp":true,"androidDeviceSerial":"ZX1G425VDZ"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"5107e10a8f8ba7b9f3c80bb60423c911","status":13,"value":{"message":"unknown error: Device ZX1G425VDZ is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19...
error: Chromedriver: Chromedriver exited unexpectedly with code null, signal SIGTERM
info: Chromedriver: Changed state to 'stopped'
warn: Chromedriver for context WEBVIEW_com.ridewith stopped unexpectedly
warn: Chromedriver quit unexpectedly, but it wasn't the active context, ignoring
error: Chromedriver: Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Device ZX1G425VDZ is not online
  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.2 x86_64))
    at JWProxy.command$ (lib/proxy.js:133:15)
    at tryCatch (/Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/appium-jsonwp-proxy/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/appium-jsonwp-proxy/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/appium-jsonwp-proxy/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/appium-jsonwp-proxy/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at bound (domain.js:254:14)
    at GeneratorFunctionPrototype.runBound (domain.js:267:12)
    at run (/Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/appium-jsonwp-proxy/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:89:39)
    at /Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/appium-jsonwp-proxy/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:100:28
    at flush (/Users/eladb/.npm-packages/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/appium-jsonwp-proxy/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:17:13)
    at process._tickDomainCallback (node.js:381:11)
 { [Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Device ZX1G425VDZ is not online
  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.2 x86_64))]
  status: 13,
  value: { message: 'unknown error: Device ZX1G425VDZ is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.2 x86_64)' },
  httpCode: 200 }

the same issue is happening with me. Any ideas what is happening? Appium returns back the context as webview_undefined and when I set to that, it says context not available .