{"record":{"id":"99514f9eb32a8ba7","repo":"angular/components","slug":"could-not-find-radio-button-matching-json-string","errorCode":null,"errorMessage":"Could not find radio button matching ${JSON.stringify(filter)}","messagePattern":"Could not find radio button matching (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material/radio/testing/radio-harness.ts","lineNumber":103,"sourceCode":"  }\n\n  /**\n   * Gets a list of radio buttons which are part of the radio-group.\n   * @param filter Optionally filters which radio buttons are included.\n   */\n  async getRadioButtons(filter?: RadioButtonHarnessFilters): Promise<MatRadioButtonHarness[]> {\n    return this.locatorForAll(this._buttonClass.with(filter))();\n  }\n\n  /**\n   * Checks a radio button in this group.\n   * @param filter An optional filter to apply to the child radio buttons. The first tab matching\n   *     the filter will be selected.\n   */\n  async checkRadioButton(filter?: RadioButtonHarnessFilters): Promise<void> {\n    const radioButtons = await this.getRadioButtons(filter);\n    if (!radioButtons.length) {\n      throw Error(`Could not find radio button matching ${JSON.stringify(filter)}`);\n    }\n    return radioButtons[0].check();\n  }\n\n  /** Gets the name attribute of the host element. */\n  private async _getGroupNameFromHost() {\n    return (await this.host()).getAttribute('name');\n  }\n\n  /** Gets a list of the name attributes of all child radio buttons. */\n  private async _getNamesFromRadioButtons(): Promise<string[]> {\n    const groupNames: string[] = [];\n    for (let radio of await this.getRadioButtons()) {\n      const radioName = await radio.getName();\n      if (radioName !== null) {\n        groupNames.push(radioName);\n      }\n    }","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/radio/testing/radio-harness.ts#L85-L121","documentation":"MatRadioGroupHarness `checkRadioButton()` throws when `getRadioButtons(filter)` returns an empty array, i.e. no child radio button matches the given filter object. It then cannot call `check()` on the first match.","triggerScenarios":"`await groupHarness.checkRadioButton({label: 'Option 2'})` where no button's label matches, the group rendered no buttons, or filter text differs in case/whitespace.","commonSituations":"Label text changed in template; using `label` vs `selector` filters incorrectly; radios not rendered due to `*ngIf`; testing a group fixture without the buttons added.","solutions":["Log `await groupHarness.getRadioButtons()` and align the filter with actual labels","Fix spelling/casing of the filter text","Ensure the radio buttons are rendered (check `*ngIf` conditions and test data)"],"exampleFix":"// before\nawait group.checkRadioButton({label: 'Opption A'});\n// after\nawait group.checkRadioButton({label: 'Option A'});","handlingStrategy":"validation","validationCode":"const buttons = await groupHarness.getRadioButtons(filter);\nif (!buttons.length) {\n  throw new Error(`No radio button matches ${JSON.stringify(filter)}`);\n}","typeGuard":"function isNonEmpty<T>(arr: T[]): arr is [T, ...T[]] { return arr.length > 0; }","tryCatchPattern":"try {\n  await groupHarness.checkRadioButton({label: 'Option A'});\n} catch (e) {\n  if (String(e?.message).startsWith('Could not find radio button matching')) {\n    fail(`Filter ${JSON.stringify(filter)} matched no radio button`);\n  }\n  throw e;\n}","preventionTips":["Share label constants between template and tests","Verify radios are rendered (*ngIf) before querying","Prefer exact labels and avoid regex filters unless needed"],"tags":["angular","material","radio","testing","harness"],"backgroundTag":"harness-element-not-found","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}