Saturday, August 24, 2024

Checkbox Handling Using Selenium Java MCQ

 MCQs on Checkbox Handling Using Selenium Java

Which Selenium WebDriver method is used to select a checkbox? 

a) check()

b) click()

c) select()

d) choose()


Answer: b) click()


How do you verify if a checkbox is selected in Selenium WebDriver? 

a) isSelected()

b) isChecked()

c) isEnabled()

d) isVisible()


Answer: a) isSelected()


Which method would you use to ensure that a checkbox is displayed on the webpage? 

a) isVisible()

b) isDisplayed()

c) isEnabled()

d) isPresent()


Answer: b) isDisplayed()


How can you select a checkbox using its ID attribute in Selenium WebDriver? 

a) driver.findElement(By.id("checkbox1")).click();

b) driver.findElement(By.name("checkbox1")).click();

c) driver.findElement(By.className("checkbox1")).click();

d) driver.findElement(By.tagName("checkbox")).click();


Answer: a) driver.findElement(By.id("checkbox1")).click();


Which exception is thrown if a checkbox element is not found on the page? 

a) ElementNotVisibleException

b) NoSuchElementException

c) ElementNotSelectableException

d) TimeoutException


Answer: b) NoSuchElementException


How would you locate a checkbox using its name attribute and select it? 

a) driver.findElement(By.name("remember")).click();

b) driver.findElement(By.id("remember")).click();

c) driver.findElement(By.className("remember")).click();

d) driver.findElement(By.xpath("//input[@name='remember']")).click();


Answer: a) driver.findElement(By.name("remember")).click();


If a checkbox is selected by default, how can you deselect it using Selenium WebDriver? 

a) click()

b) deselect()

c) uncheck()

d) select(false)


Answer: a) click()





What happens when you try to click on a disabled checkbox in Selenium? 

a) It selects the checkbox without any error.

b) It throws ElementNotInteractableException.

c) It throws NoSuchElementException.

d) It throws InvalidElementStateException.


Answer: d) It throws InvalidElementStateException.


Which method would you use to check if a checkbox is enabled? 

a) isEnabled()

b) isSelected()

c) isVisible()

d) isDisplayed()

Answer: a) isEnabled()


Which of the following will ensure a checkbox is not selected before performing an action? 

a) if (!checkbox.isEnabled()) { checkbox.click(); }

b) if (!checkbox.isSelected()) { checkbox.click(); }

c) if (checkbox.isDisplayed()) { checkbox.click(); }

d) if (checkbox.isVisible()) { checkbox.click(); }

Answer: b) if (!checkbox.isSelected()) { checkbox.click(); }



What will getAttribute("checked") return when a checkbox is selected? 

a) "true"

b) "checked"

c) null

d) "selected"

Answer: b) "checked"


To select a checkbox using CSS Selector, which of the following is correct? 

a) driver.findElement(By.cssSelector("input[name='subscribe']")).click();

b) driver.findElement(By.cssSelector("checkbox[name='subscribe']")).click();

c) driver.findElement(By.cssSelector("div[name='subscribe']")).click();

d) driver.findElement(By.cssSelector("span[name='subscribe']")).click();

Answer: a) driver.findElement(By.cssSelector("input[name='subscribe']")).click();


What will happen if you try to retrieve the text of a checkbox label using getText()? 

a) Returns "true" or "false"

b) Returns the checkbox state (checked or unchecked)

c) Returns the text label associated with the checkbox

d) Throws an exception

Answer: c) Returns the text label associated with the checkbox


Which of the following statements will find and click on the first checkbox in a list of checkboxes? 

a) driver.findElements(By.name("check")).get(0).click();

b) driver.findElements(By.id("check")).get(0).click();

c) driver.findElements(By.className("check")).get(0).click();

d) driver.findElements(By.tagName("check")).get(0).click();

Answer: a) driver.findElements(By.name("check")).get(0).click();


To clear a checkbox that is already selected, which method is used? 

a) clear()

b) uncheck()

c) click()

d) deselect()

Answer: c) click()


How can you ensure a specific checkbox is selected among multiple checkboxes with the same name attribute? 

a) Use findElements and iterate through all checkboxes.

b) Use findElement with By.name and click on it directly.

c) Use By.className to find the correct checkbox.

d) Use By.id to find the correct checkbox.

Answer: a) Use findElements and iterate through all checkboxes.

No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...