{"record":{"id":"e49a86c5aca78bda","repo":"karatelabs/karate","slug":"no-tab-found-matching-titleorurl","errorCode":null,"errorMessage":"No tab found matching: ${titleOrUrl}","messagePattern":"No tab found matching: (.+?)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java","lineNumber":358,"sourceCode":"                throw new DriverException(\"Tab index out of bounds: \" + index\n                        + \" (available: \" + handles.size() + \")\");\n            }\n        } else if (target instanceof String) {\n            String titleOrUrl = (String) target;\n            String currentHandle = session.getWindowHandle();\n            List<String> handles = session.getWindowHandles();\n            for (String handle : handles) {\n                session.switchWindow(handle);\n                String title = session.getTitle();\n                String url = session.getUrl();\n                if ((title != null && title.contains(titleOrUrl))\n                        || (url != null && url.contains(titleOrUrl))) {\n                    return; // Found it\n                }\n            }\n            // Not found, restore original\n            session.switchWindow(currentHandle);\n            throw new DriverException(\"No tab found matching: \" + titleOrUrl);\n        }\n    }\n\n    // ========== Element Operations ==========\n    //\n    // V1 PATTERN: Almost all element operations use JS eval, NOT native W3C element endpoints.\n    // This was a deliberate, battle-tested choice in v1:\n    //   - click() uses JS .click() — more reliable across browsers than POST /element/{id}/click\n    //   - text/html/value/attribute/enabled all use JS — avoids stale element reference issues\n    //   - clear() uses JS value = '' — more consistent than POST /element/{id}/clear\n    //   - ONLY input() uses native W3C sendKeys — because JS can't simulate real keyboard events\n    //     that trigger framework event handlers (React, Vue, Angular)\n    //\n    // The single-retry pattern in eval() provides the retry safety net for all JS operations.\n\n    @Override\n    public Element click(String locator) {\n        // v1 pattern: JS click, not W3C endpoint — more reliable, handles shadow DOM, custom elements","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java#L340-L376","documentation":"W3cDriver.tab(target) with a String target iterates all window handles, switching to each and testing whether its title or URL contains the given text. If no tab matches, it restores the original handle and throws DriverException 'No tab found matching: <titleOrUrl>'. Matching is substring-based and case/whitespace-sensitive.","triggerScenarios":"Calling tab('Some Title') or tab('/some/path') when no open tab's title or URL contains that exact substring — wrong casing, partial/split text, URL-encoded characters, or the target tab never opened.","commonSituations":"Page title differs from the visible heading (browser tab title vs h1); URL fragments or query params encoded (e.g. %20 vs space); popup opened in a new window the driver doesn't track; title changed dynamically after load; trailing whitespace in the search string.","solutions":["Print the open tabs' titles/URLs (windowHandles + getTitle/getUrl per handle) and match a substring that actually appears","Match on a stable URL fragment instead of a volatile title","Wait for the target tab to finish loading before searching","Trim/normalize the search string and account for URL encoding"],"exampleFix":"// before\ntab('My Account Dashboard'); // h1 text, not the tab title\n// after\ntab('/account/dashboard'); // stable URL substring","handlingStrategy":"validation","validationCode":"// confirm a matching tab exists before switching\nboolean found = driver.windowHandles().stream().anyMatch(h ->\n    driver.getTitle(h).contains(expected) || driver.getUrl(h).contains(expected));\nif (!found) throw new AssertionError(\"no tab matching \" + expected);","typeGuard":null,"tryCatchPattern":"try {\n    driver.tab(titleOrUrl);\n} catch (DriverException e) {\n    if (e.getMessage().startsWith(\"No tab found matching\")) {\n        // dump handles/titles for diagnosis, then use index fallback\n    } else throw e;\n}","preventionTips":["Match on stable URL fragments, not display headings","Remember matching is substring- and case-sensitive","Wait for the target tab to load before searching","Normalize/trim search strings and account for URL encoding"],"tags":["tab","not-found","webdriver","window-handling"],"backgroundTag":"entity-not-found","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}