Automation practice form
Practice the controls every form has: a validated input, radio buttons, a checkbox, a file upload, a slider and a date field, each built well and built to break. Open the shop checkout
Input with validationType something that is not an email, then leave the field.
Built well
Built to break
Radio buttons
Built well
Built to break
Checkbox
Built well
Built to break
File uploadThe fragile one hides its real input.
Built well
Built to break
Slider and date
Built well
Built to break
Tasks: write a locator, get a grade
How to locate Form controls
Forms look simple until the controls are custom
A labelled native input is the easiest element on the web to locate. Forms get hard when the label is missing and the only text is a placeholder, which disappears as soon as someone types, or when the id is generated by a component library and changes every build. The fragile fields here do both.
Custom radios and checkboxes are divs that look like controls. They have no checkbox or radio role, and the checked state lives in a class name or a check mark glyph, so a test cannot ask whether the box is checked. The well-built forms use native inputs inside their labels.
File uploads are often a styled drop zone with the real <input type="file"> hidden behind it. Every tool uploads by setting files on that input, so a test has to find the hidden input, not the visible zone.
Sliders built from divs have no value a tool can set; the only way to move them is to drag by coordinates, which breaks at a different window size. Date fields vary by browser: a native date input takes keystrokes in the browser’s own order, while a text box wants a format only its placeholder explains.
Validation errors that are not tied to their field leave a test guessing which message belongs to which input. A well-built field marks itself aria-invalid and points to its message with aria-describedby.
What a stable locator looks like
Find each control by its label, then use the tool’s own action for that control: check a checkbox, select a radio, set files on the file input. Assert validation through aria-invalid and the field’s accessible description, not by position on the page.
const email = page.getByLabel('Work email');
await email.fill('not-an-email');
await email.blur();
await expect(email).toHaveAttribute('aria-invalid', 'true');
await expect(email).toHaveAccessibleDescription('Enter a valid email.');
await page.getByRole('radio', { name: 'Pro' }).check();
await page.getByRole('checkbox', { name: 'Subscribe to the newsletter' }).check();
await page.getByLabel('Product image').setInputFiles('fixtures/shoe.png');
await page.getByRole('slider', { name: /Stock level/ }).press('ArrowRight');
await page.getByLabel('Delivery date').fill('2026-12-24');In a real workflow
The shop’s checkout mixes these controls: labelled address fields beside fragile ones, a fragile delivery choice, a native date field and the card form. Sign in, add a product, and fill the checkout from top to bottom.
COR Lens generates locators for shadow DOM, iframes and tables, and grades each one. Click the form controls above with it and compare its pick with yours.
Add to Chrome