0
0
Selenium Javatesting~10 mins

Radio button handling in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select a radio button by its ID.

Selenium Java
WebElement radioBtn = driver.findElement(By.id("genderMale"));
radioBtn.[1]();
Drag options to blanks, or click blank then click option'
Aclick
Bsubmit
CgetText
DsendKeys
Attempts:
3 left
💡 Hint
Common Mistakes
Using submit() which is for forms, not radio buttons.
Using sendKeys() which is for typing text.
2fill in blank
medium

Complete the code to check if a radio button is selected.

Selenium Java
boolean isSelected = driver.findElement(By.name("color")).[1]();
Drag options to blanks, or click blank then click option'
AisDisplayed
BgetAttribute
CisSelected
DisEnabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using isDisplayed() which checks visibility, not selection.
Using getAttribute() without specifying the attribute.
3fill in blank
hard

Fix the error in the code to select a radio button by XPath.

Selenium Java
driver.findElement(By.xpath("//input[@type='radio' and @value='Female']")).[1]();
Drag options to blanks, or click blank then click option'
AsendKeys
Bclick
CgetText
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendKeys() which is for typing text.
Using getText() which returns text content.
4fill in blank
hard

Fill both blanks to select a radio button by CSS selector and verify it is selected.

Selenium Java
WebElement radio = driver.findElement(By.[1]("input[name='subscription'][value='yes']"));
boolean selected = radio.[2]();
Drag options to blanks, or click blank then click option'
AcssSelector
BisDisplayed
CisSelected
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using id when the locator is a CSS selector.
Using isDisplayed() instead of isSelected() to check selection.
5fill in blank
hard

Fill all three blanks to select a radio button by XPath, click it, and assert it is selected.

Selenium Java
WebElement radioBtn = driver.findElement(By.[1]("//input[@name='payment' and @value='credit']"));
radioBtn.[2]();
assertTrue(radioBtn.[3]());
Drag options to blanks, or click blank then click option'
Axpath
Bclick
CisSelected
DcssSelector
Attempts:
3 left
💡 Hint
Common Mistakes
Using cssSelector instead of xpath for the locator.
Forgetting to click the radio button before asserting.
Using isDisplayed() instead of isSelected() in the assertion.