MCQs on Interacting with Web Elements | Selenium

Introduction: Master Selenium Web Interactions for Automation
Learn to interact with web elements effectively in Selenium. These 30 MCQs cover working with input boxes, buttons, links, checkboxes, radio buttons, dropdowns, and the Select class for web automation.


Interacting with Web Elements in Selenium – MCQs

1. Working with Input Boxes, Buttons, and Links (10 Questions)

  1. Which method in Selenium is used to send text to an input box?
    a) setValue()
    b) sendKeys()
    c) type()
    d) inputText()
  2. How can you click a button using Selenium?
    a) clickButton()
    b) press()
    c) click()
    d) actionClick()
  3. What Selenium method retrieves the text of a web element?
    a) getText()
    b) retrieveText()
    c) fetchText()
    d) extractText()
  4. Which of the following locators can be used to find a link by its visible text?
    a) By.xpath
    b) By.linkText
    c) By.cssSelector
    d) By.partialLinkText
  5. What is the purpose of clear() in Selenium?
    a) To delete cookies
    b) To remove text from an input box
    c) To close a browser
    d) To reset a form
  6. How can you submit a form using Selenium?
    a) submitForm()
    b) sendKeys(Keys.ENTER)
    c) submit()
    d) pressEnter()
  7. What does the isDisplayed() method check?
    a) If an element is clickable
    b) If an element is visible on the page
    c) If an element has the correct text
    d) If an element is selected
  8. What exception is thrown if an element is not found in Selenium?
    a) NoSuchElementException
    b) ElementNotFoundException
    c) LocatorNotFoundException
    d) InvalidElementException
  9. Which Selenium method is used to get an attribute’s value from a web element?
    a) getValue()
    b) getAttribute()
    c) fetchAttribute()
    d) attribute()
  10. How do you simulate a keypress in an input field using Selenium?
    a) pressKey()
    b) sendKeys()
    c) typeKey()
    d) simulateKey()

2. Handling Checkboxes and Radio Buttons (10 Questions)

  1. How do you select a checkbox in Selenium?
    a) selectCheckbox()
    b) click()
    c) setChecked()
    d) check()
  2. What method can you use to verify if a checkbox is selected?
    a) isChecked()
    b) isSelected()
    c) isEnabled()
    d) isClicked()
  3. What is the correct way to select a radio button?
    a) selectRadio()
    b) click()
    c) setRadio()
    d) choose()
  4. Which of the following locators is most suitable for finding a group of checkboxes?
    a) By.id
    b) By.className
    c) By.cssSelector
    d) By.xpath
  5. How can you deselect a checkbox?
    a) uncheck()
    b) click()
    c) setUnchecked()
    d) Selenium does not require a special method; use click()
  6. What does the isEnabled() method in Selenium check?
    a) If a checkbox is selected
    b) If a web element is clickable
    c) If a checkbox is deselected
    d) If an input field is editable
  7. How can you handle multiple checkboxes on a webpage using Selenium?
    a) Use findElements() to get a list of all checkboxes
    b) Use findElement() and loop through checkboxes
    c) Use selectAllCheckboxes()
    d) Use getAllCheckboxes()
  8. How do you locate a radio button by its value in Selenium?
    a) By.xpath with the value attribute
    b) By.cssSelector with the value attribute
    c) Both a and b
    d) By.id
  9. Which of the following methods is used to toggle the state of a checkbox?
    a) toggle()
    b) click()
    c) switch()
    d) setChecked()
  10. How do you verify if a specific checkbox or radio button is clickable?
    a) isClickable()
    b) isEnabled()
    c) canBeClicked()
    d) isInteractable()

3. Dropdowns and Select Class (10 Questions)

  1. Which class in Selenium is used to handle dropdowns?
    a) Dropdown
    b) Select
    c) DropdownHandler
    d) WebDropdown
  2. How can you select an option in a dropdown by its visible text?
    a) selectByText()
    b) selectByVisibleText()
    c) chooseByText()
    d) pickByText()
  3. How do you select an option in a dropdown by its index?
    a) selectByIndex()
    b) chooseByIndex()
    c) pickByIndex()
    d) selectOptionByIndex()
  4. How do you select a value from a dropdown by its value attribute?
    a) selectByValue()
    b) selectOptionByValue()
    c) selectValue()
    d) chooseValue()
  5. Which method retrieves all options from a dropdown?
    a) getOptions()
    b) retrieveOptions()
    c) fetchOptions()
    d) listOptions()
  6. What does the isMultiple() method of the Select class check?
    a) If a dropdown allows multiple selections
    b) If a dropdown has more than one option
    c) If a dropdown is editable
    d) If a dropdown has a search feature
  7. How do you deselect all options in a multi-select dropdown?
    a) deselectAll()
    b) clearAllSelections()
    c) resetAll()
    d) removeAll()
  8. Which method is used to deselect an option by its visible text in a multi-select dropdown?
    a) deselectByText()
    b) deselectByVisibleText()
    c) removeByText()
    d) unselectByText()
  9. How can you iterate over all options in a dropdown?
    a) Using forEach on getOptions()
    b) Using a loop with getOptions()
    c) Both a and b
    d) Using listAllOptions()
  10. Which method retrieves the currently selected option in a dropdown?
    a) getSelectedOption()
    b) getFirstSelectedOption()
    c) getActiveOption()
    d) fetchSelectedOption()

Answers

QnoAnswer
1b) sendKeys()
2c) click()
3a) getText()
4b) By.linkText
5b) To remove text from an input box
6c) submit()
7b) If an element is visible on the page
8a) NoSuchElementException
9b) getAttribute()
10b) sendKeys()
11b) click()
12b) isSelected()
13b) click()
14d) By.xpath
15d) Selenium does not require a special method; use click()
16b) If a web element is clickable
17a) Use findElements() to get a list of all checkboxes
18c) Both a and b
19b) click()
20b) isEnabled()
21b) Select
22b) selectByVisibleText()
23a) selectByIndex()
24a) selectByValue()
25a) getOptions()
26a) If a dropdown allows multiple selections
27a) deselectAll()
28b) deselectByVisibleText()
29c) Both a and b
30b) getFirstSelectedOption()

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top