0
0
Selenium Javatesting~10 mins

Radio button handling in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web page with radio buttons, selects a specific radio button, and verifies that it is selected.

Test Code - JUnit with Selenium WebDriver
Selenium Java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class RadioButtonTest {
    WebDriver driver;

    @BeforeEach
    public void setUp() {
        driver = new ChromeDriver();
        driver.get("https://example.com/radio-buttons");
    }

    @Test
    public void testSelectRadioButton() {
        WebElement radioButton = driver.findElement(By.id("option2"));
        radioButton.click();
        assertTrue(radioButton.isSelected(), "Radio button option2 should be selected");
    }

    @AfterEach
    public void tearDown() {
        driver.quit();
    }
}
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensChrome browser window is open, ready to navigate-PASS
2Navigates to https://example.com/radio-buttonsPage with radio buttons is loaded and visiblePage title or URL confirms correct page loadedPASS
3Finds radio button element with id 'option2'Radio button with id 'option2' is located in the DOMElement is present and interactablePASS
4Clicks on the radio button 'option2'Radio button 'option2' is selected visually-PASS
5Checks if radio button 'option2' is selectedRadio button 'option2' state is selectedassertTrue(radioButton.isSelected()) verifies selectionPASS
6Test ends and browser closesBrowser window is closed-PASS
Failure Scenario
Failing Condition: Radio button with id 'option2' is not found or not clickable
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the radio button?
AThat the radio button is disabled
BThat the radio button is visible
CThat the radio button is selected
DThat the radio button is unchecked
Key Result
Always verify that the element is present and interactable before clicking, and assert the expected state after interaction to confirm correct behavior.