{"record":{"id":"2c1ee0c5e12f69c6","repo":"karatelabs/karate","slug":"webdriver-request-method-request-uri-getpath-failed-response","errorCode":null,"errorMessage":"WebDriver \" + request.method() + \" \" + request.uri().getPath() + \" failed (\" + response.statusCode() + \"): \" + message","messagePattern":"WebDriver \" \\+ request\\.method\\(\\) \\+ \" \" \\+ request\\.uri\\(\\)\\.getPath\\(\\) \\+ \" failed \\(\" \\+ response\\.statusCode\\(\\) \\+ \"\\): \" \\+ message","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cSession.java","lineNumber":454,"sourceCode":"                java.util.HashMap<String, Object> nullResult = new java.util.HashMap<>();\n                nullResult.put(\"value\", null);\n                return nullResult;\n            }\n            Map<String, Object> result = Json.of(body).asMap();\n\n            // Check for W3C error response\n            if (response.statusCode() >= 400) {\n                Object value = result.get(\"value\");\n                String message = \"WebDriver error\";\n                if (value instanceof Map) {\n                    Map<String, Object> errorMap = (Map<String, Object>) value;\n                    message = (String) errorMap.getOrDefault(\"message\", message);\n                    String error = (String) errorMap.get(\"error\");\n                    if (error != null) {\n                        message = error + \": \" + message;\n                    }\n                }\n                throw new DriverException(\"WebDriver \" + request.method() + \" \"\n                        + request.uri().getPath() + \" failed (\" + response.statusCode() + \"): \" + message);\n            }\n\n            return result;\n        } catch (DriverException e) {\n            throw e;\n        } catch (IOException | InterruptedException e) {\n            if (e instanceof InterruptedException) {\n                Thread.currentThread().interrupt();\n            }\n            throw new DriverException(\"WebDriver request failed: \" + request.method() + \" \"\n                    + request.uri() + \": \" + e.getMessage(), e);\n        }\n    }\n\n    private static Object getValue(Map<String, Object> response) {\n        return response.get(\"value\");\n    }","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cSession.java#L436-L472","documentation":"This DriverException is thrown when a WebDriver command executed over HTTP returns a non-success status code. W3cSession.execute() parses the WebDriver error payload and prefixes the message with the failing HTTP method, endpoint path and status code, so the developer sees exactly which remote command failed and the driver-reported reason.","triggerScenarios":"Any get(), postRaw() or delete() call on a W3cSession whose HTTP response status is not success — e.g. clicking a stale element, switching to a closed window, or a command the driver endpoint does not support. Server-side error maps may include 'error' and 'message' keys which are merged into the thrown message.","commonSituations":"Stale element references after DOM updates, timeouts during navigation, invalid selectors, interacting with a browser session that crashed or was closed, or hitting an endpoint unsupported by the browser/driver version in use.","solutions":["Read the driver-reported message after the status code — it names the concrete WebDriver error (e.g. stale element reference, no such window) and fix the root cause","Re-locate the element before interacting if the error is stale-element","Check that the chromedriver/geckodriver version matches the installed browser version","Add appropriate implicit/explicit wait before the failing command"],"exampleFix":"// before\ndriver.locate(\"#item\").click(); // fails after DOM re-render\n// after\ndriver.waitFor(\"#item\").click();","handlingStrategy":"try-catch","validationCode":"// before calling any driver command, ensure session is alive\nif (session == null || !session.isAlive()) {\n    session = new W3cSession(options);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Object res = session.get(url);\n} catch (DriverException e) {\n    // message contains method, path, status and driver-reported reason\n    if (e.getMessage().contains(\"stale element reference\")) {\n        element = driver.waitFor(selector);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Use explicit waits before interacting with elements","Re-locate elements after DOM mutations","Keep driver version matched to browser version","Wrap remote commands in retry logic for transient failures"],"tags":["webdriver","selenium-driver","browser-automation","http-error"],"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"}