{"record":{"id":"949bebab4b2eaff6","repo":"karatelabs/karate","slug":"webdriver-session-create-failed-with-status-response","errorCode":null,"errorMessage":"WebDriver session create failed with status \" + response.statusCode() + \": \" + response.body()","messagePattern":"WebDriver session create failed with status \" \\+ response\\.statusCode\\(\\) \\+ \": \" \\+ response\\.body\\(\\)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cSession.java","lineNumber":112,"sourceCode":"        HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()\n                .uri(uri)\n                .header(\"Content-Type\", \"application/json; charset=utf-8\")\n                .timeout(timeout);\n\n        String userInfo = uri.getUserInfo();\n        if (userInfo != null && !userInfo.isBlank()) {\n            String basicAuth = \"Basic \" + Base64.getEncoder().encodeToString(userInfo.getBytes());\n            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        }","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cSession.java#L94-L130","documentation":"W3cSession.create posts the new-session payload to the WebDriver endpoint and throws DriverException when the HTTP response status is not 200, embedding the status code and response body. This surfaces driver-side rejections of session creation (bad capabilities, unsupported browser, driver not running correctly).","triggerScenarios":"POST /session to the WebDriver server returns 4xx/5xx — mismatched or invalid capabilities JSON, unsupported browser version, driver bound to a different browser path, or malformed W3C payload.","commonSituations":"chromedriver older than the installed Chrome (capabilities rejected); wrong w3c capabilities keys; connecting to a grid that rejects the requested platform; driver process is up but its browser binary path is wrong.","solutions":["Read the response body in the message — WebDriver errors explain the rejected capability or missing binary","Update the browser and driver to matching versions (chromedriver ↔ Chrome, geckodriver ↔ Firefox)","Verify the capabilities/options being sent are valid W3C session capabilities","Confirm the WebDriver endpoint URL and that the server responds to /status"],"exampleFix":"// before\nMap<String, Object> opts = MapUtils.of(\"type\", \"chromedriver\", \"chromedriverPath\", \"/old/path/chromedriver\");\n// after — matching driver version\nMap<String, Object> opts = MapUtils.of(\"type\", \"chromedriver\", \"chromedriverPath\", \"/usr/local/bin/chromedriver\");\n// and align installed Chrome version with the driver version","handlingStrategy":"retry","validationCode":"// pre-check the WebDriver endpoint\nHttpRequest req = HttpRequest.newBuilder(URI.create(baseUrl + \"/status\")).GET().build();\n// require HTTP 200 and value.ready == true before creating a session","typeGuard":null,"tryCatchPattern":"try {\n    session = W3cSession.create(client, baseUrl, caps, timeout);\n} catch (DriverException e) {\n    // message includes HTTP status + body: fix capabilities or versions, then retry\n}","preventionTips":["Keep browser and driver versions matched","Validate capabilities against W3C spec before sending","Check driver logs for the rejection reason"],"tags":["webdriver","session","http-error","capabilities"],"backgroundTag":"http-error-response","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"}