Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
submit() which is for forms, not radio buttons.Using
sendKeys() which is for typing text.✗ Incorrect
The click() method is used to select a radio button in Selenium.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
isDisplayed() which checks visibility, not selection.Using
getAttribute() without specifying the attribute.✗ Incorrect
The isSelected() method returns true if the radio button is selected.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
sendKeys() which is for typing text.Using
getText() which returns text content.✗ Incorrect
To select a radio button, you must use click() to simulate the user clicking it.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
id when the locator is a CSS selector.Using
isDisplayed() instead of isSelected() to check selection.✗ Incorrect
Use cssSelector to find the element by CSS, and isSelected() to check if it is selected.
5fill in blank
hardFill 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'
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.✗ Incorrect
Find the element by xpath, click it to select, then assert it is selected with isSelected().