Saturday, August 24, 2024

Handling Dropdowns or List Boxes Using Selenium Java MCQ

 MCQs on Handling Dropdowns or List Boxes Using Selenium Java

Which Selenium class is specifically used for handling dropdowns in Java?


a) WebElement

b) Select

c) Dropdown

d) WebDriver

Answer: b) Select


What is the correct way to initialize a dropdown using Selenium's Select class in Java?


a) Select dropdown = new Select(driver.findElement(By.id("dropdownId")));

b) WebElement dropdown = driver.findElement(By.id("dropdownId"));

c) Dropdown dropdown = new Select(driver.findElement(By.id("dropdownId")));

d) Select dropdown = driver.findElement(By.id("dropdownId"));

Answer: a) Select dropdown = new Select(driver.findElement(By.id("dropdownId")));


Which method is used to select an option from a dropdown by its visible text?


a) selectByValue()

b) selectByVisibleText()

c) selectByIndex()

d) getOptions()

Answer: b) selectByVisibleText()


How can you select an option from a dropdown by its index?


a) dropdown.selectByText(int index);

b) dropdown.selectByIndex(int index);

c) dropdown.selectByValue(int index);

d) dropdown.selectByVisibleText(int index);

Answer: b) dropdown.selectByIndex(int index);


Which method is used to select an option from a dropdown by its value attribute?


a) selectByText()

b) selectByVisibleText()

c) selectByIndex()

d) selectByValue()

Answer: d) selectByValue()


What is the method to retrieve all options available in a dropdown?


a) getAllOptions()

b) getOptions()

c) retrieveOptions()

d) getAvailableOptions()

Answer: b) getOptions()


How can you retrieve the first selected option from a dropdown using Selenium?


a) getFirstSelectedOption()

b) getSelectedOption()

c) getFirstOption()

d) getFirstSelected()

Answer: a) getFirstSelectedOption()


What will the isMultiple() method of the Select class return?


a) true if the dropdown allows multiple selections

b) false if the dropdown allows multiple selections

c) The number of options in the dropdown

d) null if no option is selected

Answer: a) true if the dropdown allows multiple selections


Which exception is thrown if an option is not found in the dropdown?


a) NoSuchElementException

b) ElementNotFoundException

c) NoSuchOptionException

d) OptionNotFoundException

Answer: a) NoSuchElementException


How do you deselect all selected options in a multi-select dropdown?


a) deselectAll()

b) deselectOptions()

c) clearSelections()

d) deselectAllOptions()

Answer: a) deselectAll()


Which method would you use to deselect an option by its index in a multi-select dropdown?


a) deselectByText(int index)

b) deselectByIndex(int index)

c) deselectByValue(int index)

d) deselectByVisibleText(int index)

Answer: b) deselectByIndex(int index)


How do you verify if a dropdown is a multi-select dropdown?


a) Use the getOptions() method

b) Use the isMultiple() method

c) Use the checkMultiSelect() method

d) Use the isMultiSelect() method

Answer: b) Use the isMultiple() method


What is the purpose of the deselectByVisibleText() method in a multi-select dropdown?


a) To select an option by its visible text

b) To deselect an option by its value

c) To deselect an option by its visible text

d) To remove all selections

Answer: c) To deselect an option by its visible text


If you want to select multiple options in a dropdown by their values, which method would you use?


a) selectByValue(String value1, String value2)

b) selectByMultipleValues(List<String> values)

c) selectByValue() in a loop

d) selectMultipleValues()

Answer: c) selectByValue() in a loop


How would you handle a scenario where the dropdown options are dynamically loaded after a delay?


a) Use Thread.sleep() to wait for the options to load

b) Use WebDriverWait with ExpectedConditions.elementToBeClickable()

c) Use driver.refresh() to reload the page

d) Use selectByIndex() method


Answer: b) Use WebDriverWait with ExpectedConditions.elementToBeClickable()


Which method of the Select class would you use to deselect all options by visible text?


a) deselectAll()

b) deselectByVisibleText()

c) deselectAllByVisibleText()

d) clearSelections()

Answer: b) deselectByVisibleText()


What is the correct syntax to select an option using the value attribute in a dropdown?


a) selectByValue("value");

b) selectByVisibleText("value");

c) selectOptionByValue("value");

d) selectValue("value");

Answer: a) selectByValue("value");


To verify if a specific option is selected in a dropdown, which method would you use?


a) isOptionSelected()

b) getFirstSelectedOption()

c) isSelected()

d) isMultiple()

Answer: b) getFirstSelectedOption()



How can you verify that a dropdown does not allow multiple selections?


a) Use the isMultiple() method and check for false

b) Use the isSingle() method

c) Check if getOptions() returns more than one option

d) Use the verifySingleSelection() method

Answer: a) Use the isMultiple() method and check for false

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...