{"record":{"id":"e88dc30fa4cb36bb","repo":"jhy/jsoup","slug":"matchtext-is-no-longer-supported-use-element-sel","errorCode":null,"errorMessage":":matchText is no longer supported. Use Element#selectNodes(String, Class) with selector ::text and class TextNode instead.","messagePattern":":matchText is no longer supported\\. Use Element#selectNodes\\(String, Class\\) with selector ::text and class TextNode instead\\.","errorType":"exception","errorClass":"Selector.SelectorParseException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/select/QueryParser.java","lineNumber":259,"sourceCode":"                return new Evaluator.IsFirstChild();\n            case \"last-child\":\n                return new Evaluator.IsLastChild();\n            case \"first-of-type\":\n                return new Evaluator.IsFirstOfType();\n            case \"last-of-type\":\n                return new Evaluator.IsLastOfType();\n            case \"only-child\":\n                return new Evaluator.IsOnlyChild();\n            case \"only-of-type\":\n                return new Evaluator.IsOnlyOfType();\n            case \"empty\":\n                return new Evaluator.IsEmpty();\n            case \"blank\":\n                return new NodeEvaluator.BlankValue();\n            case \"root\":\n                return new Evaluator.IsRoot();\n            case \"matchText\": {\n                throw new Selector.SelectorParseException(\":matchText is no longer supported. Use Element#selectNodes(String, Class) with selector ::text and class TextNode instead.\"); // todo remove this in 1.25.1\n            }\n            default:\n                throw new Selector.SelectorParseException(\"Could not parse query '%s': unexpected token at '%s'\", query, tq.remainder());\n        }\n    }\n\n    // ::comment etc\n    private Evaluator parseNodeSelector() {\n        final String pseudo = tq.consumeCssIdentifier();\n        inNodeContext = true;  // Enter node context\n\n        Evaluator left;\n        switch (pseudo) {\n            case \"node\":\n                left = new NodeEvaluator.InstanceType(Node.class, pseudo);\n                break;\n            case \"leafnode\":\n                left = new NodeEvaluator.InstanceType(LeafNode.class, pseudo);","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/select/QueryParser.java#L241-L277","documentation":"jsoup's CSS selector parser no longer accepts the :matchText pseudo-selector; it was deprecated and now throws Selector.SelectorParseException when parsed. The replacement is Element#selectNodes(String, Class) using a ::text node selector with TextNode as the result class. This guard exists so old queries fail loudly instead of silently changing behavior.","triggerScenarios":"Calling Element.select(), Elements.select(), or Selector.select() with a query string containing ':matchText' (e.g. 'div:matchText'). Parsed in QueryParser.parsePseudoSelector, reached via parseSubclass.","commonSituations":"Upgrading jsoup from versions before 1.15.x where :matchText worked; queries copied from old Stack Overflow answers or legacy codebases that selected text nodes via :matchText.","solutions":["Replace the selector with Element#selectNodes(\"div ::text\", TextNode.class) and iterate the returned TextNode list","If you need the containing elements, use select(\"div:contains(...)\") or select text via Element#text()/#ownText()","Pin jsoup to an older version (<1.15) only as a temporary measure; the case is slated for removal"],"exampleFix":"// before\nElements els = doc.select(\"p:matchText\");\n// after\nList<TextNode> textNodes = doc.selectNodes(\"p ::text\", TextNode.class);","handlingStrategy":"fallback","validationCode":"if (selector.contains(\":matchText\")) {\n    List<TextNode> nodes = element.selectNodes(selector.replace(\":matchText\", \" ::text\"), TextNode.class);\n}","typeGuard":"boolean usesMatchText(String q) { return q != null && q.contains(\":matchText\"); }","tryCatchPattern":"try {\n    Elements els = doc.select(query);\n} catch (Selector.SelectorParseException e) {\n    if (e.getMessage().contains(\":matchText\")) {\n        List<TextNode> nodes = doc.selectNodes(\"div ::text\", TextNode.class);\n    } else { throw e; }\n}","preventionTips":["Grep codebases for ':matchText' before upgrading jsoup","Use Element#text()/ownText() for text extraction instead of pseudo-selectors","Pin and review jsoup release notes when upgrading"],"tags":["jsoup","css-selector","deprecation"],"backgroundTag":"deprecated-api-usage","analyzedSha":"9851ac5d9c576c6888910b5a51a2362bbc978959","analyzedAt":"2026-09-08T15:22:04.931Z","contentChangedAt":"2026-09-08T15:22:04.931Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}