I have a form built from reusable components, such that each form control is generated with a unique id which is referenced by its label:
<label for="2346157937rfl5v">Complaint</label>
<div>
<textarea id="2346157937rfl5v" [(ngModel)]="value"></textarea>
</div>
It's easy to use Cypress to identify the label element based on the text. But how can I then identify the associated form control element?
cy.contains('Complaint').???
I could just use .next().get('textarea'), but that seems too tied to the current implementation. Ideally there is some way to follow the link from the label.
Clarification: I want to identify the label element, get its for attribute, and then identify the textarea element using that id. This way the test isn't relying on the structure of the DOM.