Radio Button
Three radio buttons – one of them is disabled, which is the case people forget to test.
Do you like this demo site?
Practice tasks
- Select
Yesand assert the result text readsYou selected Yes. - Select
Impressiveand assert the result changes, and thatYesis no longer selected. - Assert that the
Noradio is disabled and cannot be selected (a click must not change the result). - Assert that no radio is selected when the page first loads.
Sample automation code
driver.findElement(By.id("yes-radio")).click();
Assert.assertEquals(driver.findElement(By.id("radio-result")).getText(), "You selected Yes");
WebElement no = driver.findElement(By.id("no-radio"));
Assert.assertFalse(no.isEnabled());
await page.getByTestId('yes').check();
await expect(page.getByTestId('radio-result')).toHaveText('You selected Yes');
await expect(page.getByTestId('no')).toBeDisabled();