{"record":{"id":"a5ae82b25622b45a","repo":"karatelabs/karate","slug":"webdriver-session-create-response-missing-sessionid-response","errorCode":null,"errorMessage":"WebDriver session create response missing sessionId: \" + response.body()","messagePattern":"WebDriver session create response missing sessionId: \" \\+ response\\.body\\(\\)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cSession.java","lineNumber":120,"sourceCode":"            requestBuilder.header(\"Authorization\", basicAuth);\n        }\n\n        HttpRequest request = requestBuilder\n                .POST(HttpRequest.BodyPublishers.ofString(json))\n                .build();\n\n        try {\n            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());\n            if (response.statusCode() != 200) {\n                throw new DriverException(\"WebDriver session create failed with status \"\n                        + response.statusCode() + \": \" + response.body());\n            }\n\n            Map<String, Object> body = Json.of(response.body()).asMap();\n            Map<String, Object> value = (Map<String, Object>) body.get(\"value\");\n            String sessionId = (String) value.get(\"sessionId\");\n            if (sessionId == null) {\n                throw new DriverException(\"WebDriver session create response missing sessionId: \" + response.body());\n            }\n\n            logger.info(\"W3C session created: {}\", sessionId);\n            return new W3cSession(client, baseUrl, sessionId, timeout);\n        } catch (IOException | InterruptedException e) {\n            if (e instanceof InterruptedException) {\n                Thread.currentThread().interrupt();\n            }\n            throw new DriverException(\"WebDriver session create failed: \" + e.getMessage(), e);\n        }\n    }\n\n    // ========== Navigation ==========\n\n    public void navigateTo(String url) {\n        post(\"url\", Map.of(\"url\", url));\n    }\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cSession.java#L102-L138","documentation":"After a 200 response, W3cSession.create parses the JSON body and throws DriverException if the `value.sessionId` field is absent, including the raw body in the message. A 200 without a sessionId is a malformed/unexpected response from whatever answered the WebDriver port.","triggerScenarios":"POST /session returns HTTP 200 but the body lacks value.sessionId — e.g. an intermediate proxy answered, the endpoint is not actually a WebDriver server, or a non-W3C (legacy JSON wire) driver returned a different body shape.","commonSituations":"Pointing the driver at the wrong port (another HTTP service listening there); corporate proxy intercepting the request; using an old driver that returns sessionId at the top level (pre-W3C protocol).","solutions":["Verify the host/port points at the real WebDriver endpoint (curl /status and inspect the response)","Inspect the echoed body in the message to see what actually replied","Use a W3C-compliant driver version (legacy JSON-wire drivers put sessionId outside value)","Bypass proxies for localhost so the request reaches the driver directly"],"exampleFix":"// before\ndriver('type', 'chromedriver', 'port', 9222); // 9222 is DevTools, not chromedriver\n// after\ndriver('type', 'chromedriver', 'port', 9515); // default chromedriver port","handlingStrategy":"validation","validationCode":"// confirm the endpoint really is WebDriver before session create\n// GET /status must return 200 with { value: { ready: true, ... } }","typeGuard":"boolean isW3cSessionBody(Map<String, Object> body) {\n    return body.get(\"value\") instanceof Map<?,?> v && v.get(\"sessionId\") instanceof String;\n}","tryCatchPattern":"try {\n    session = W3cSession.create(client, baseUrl, caps, timeout);\n} catch (DriverException e) {\n    if (e.getMessage().contains(\"missing sessionId\")) {\n        // inspect echoed body; fix host/port or driver protocol version\n    }\n}","preventionTips":["Never point the driver at a DevTools (CDP) port expecting WebDriver semantics","Bypass proxies for localhost driver traffic","Use W3C-compliant driver versions"],"tags":["webdriver","session","unexpected-response","http"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}