Complete the code to select a radio button by its ID.
WebElement radioBtn = driver.findElement(By.id("genderMale")); radioBtn.[1]();
submit() which is for forms, not radio buttons.sendKeys() which is for typing text.The click() method is used to select a radio button in Selenium.
Complete the code to check if a radio button is selected.
boolean isSelected = driver.findElement(By.name("color")).[1]();
isDisplayed() which checks visibility, not selection.getAttribute() without specifying the attribute.The isSelected() method returns true if the radio button is selected.
Fix the error in the code to select a radio button by XPath.
driver.findElement(By.xpath("//input[@type='radio' and @value='Female']")).[1]();
sendKeys() which is for typing text.getText() which returns text content.To select a radio button, you must use click() to simulate the user clicking it.
Fill both blanks to select a radio button by CSS selector and verify it is selected.
WebElement radio = driver.findElement(By.[1]("input[name='subscription'][value='yes']")); boolean selected = radio.[2]();
id when the locator is a CSS selector.isDisplayed() instead of isSelected() to check selection.Use cssSelector to find the element by CSS, and isSelected() to check if it is selected.
Fill all three blanks to select a radio button by XPath, click it, and assert it is selected.
WebElement radioBtn = driver.findElement(By.[1]("//input[@name='payment' and @value='credit']")); radioBtn.[2](); assertTrue(radioBtn.[3]());
cssSelector instead of xpath for the locator.isDisplayed() instead of isSelected() in the assertion.Find the element by xpath, click it to select, then assert it is selected with isSelected().
