MCQs on Radio Button Handling Using Selenium Java
Which Selenium WebDriver method is used to select a radio button?
a) click()
b) select()
c) choose()
d) press()
Answer: a) click()
How do you check if a radio button is selected in Selenium WebDriver? a) isSelected()
b) isChecked()
c) isEnabled()
d) isChosen()
Answer: a) isSelected()
Which method would you use to check if a radio button is displayed on the webpage?
a) isVisible()
b) isSelected()
c) isDisplayed()
d) isEnabled()
Answer: c) isDisplayed()
How can you select a radio button using its ID attribute in Selenium WebDriver?
a) driver.findElement(By.xpath("//radio[@id='radio1']")).click();
b) driver.findElement(By.id("radio1")).click();
c) driver.findElement(By.className("radio1")).click();
d) driver.findElement(By.name("radio1")).click();
Answer: b) driver.findElement(By.id("radio1")).click();
Which exception is thrown if a radio button element is not found on the page? a) ElementNotVisibleException
b) NoSuchElementException
c) ElementNotSelectableException
d) TimeoutException
Answer: b) NoSuchElementException
How would you locate a radio button using its name attribute and select it?
a) driver.findElement(By.id("radioButton")).click();
b) driver.findElement(By.name("gender")).click();
c) driver.findElement(By.className("radioButton")).click();
d) driver.findElement(By.tagName("input")).click();
Answer: b) driver.findElement(By.name("gender")).click();
If you need to verify the default selected state of a radio button, which method would you use?
a) isDefaultSelected()
b) isSelected()
c) isDefault()
d) isChosen()
Answer: b) isSelected()
Which Selenium locator strategy would you use to find a radio button using its value attribute?
a) By.linkText("radio")
b) By.xpath("//input[@value='male']")
c) By.id("radio")
d) By.className("radio")
Answer: b) By.xpath("//input[@value='male']")
What would be the correct way to interact with a disabled radio button?
a) click()
b) isEnabled()
c) sendKeys(Keys.SPACE)
d) click() will throw an exception
Answer: d) click() will throw an exception
Which of the following is true about radio buttons in HTML?
a) Multiple radio buttons with the same name can be selected at the same time.
b) Only one radio button in a group with the same name can be selected at a time.
c) Radio buttons are always disabled by default.
d) Radio buttons cannot have a default selected state.
Answer: b) Only one radio button in a group with the same name can be selected at a time.
How would you verify if a radio button is not selected?
a) !element.isEnabled()
b) !element.isSelected()
c) element.isNotSelected()
d) element.isDeselected()
Answer: b) !element.isSelected()
What will happen if you try to click on a hidden radio button in Selenium?
a) It will select the radio button without any error.
b) It will throw ElementNotVisibleException.
c) It will throw NoSuchElementException.
d) It will select the radio button after scrolling to it.
Answer: b) It will throw ElementNotVisibleException.
If you want to check whether a radio button is displayed on the screen, which of the following Selenium commands would you use?
a) element.isVisible()
b) element.isSelected()
c) element.isDisplayed()
d) element.isEnabled()
Answer: c) element.isDisplayed()
Which of the following WebDriver methods will be useful to check whether a radio button is enabled or not?
a) isSelected()
b) isEnabled()
c) isVisible()
d) isChosen()
Answer: b) isEnabled()
Which Selenium method is used to locate a radio button element by its class name?
a) By.id("radioButton")
b) By.name("radioButton")
c) By.className("radioButtonClass")
d) By.xpath("radioButton")
Answer: c) By.className("radioButtonClass")
What is the result of getAttribute("checked") on a selected radio button?
a) Returns "true"
b) Returns "checked"
c) Returns null
d) Returns "selected"
Answer: b) Returns "checked" -recheck
Which locator strategy is best when handling dynamic radio buttons generated at runtime?
a) By.id()
b) By.name()
c) By.cssSelector()
d) By.xpath()
Answer: d) By.xpath()