MCQs on Keyboard and Mouse Actions | Selenium

Keyboard and mouse interactions, powered by Selenium’s Actions class, enable testing advanced user behaviors like drag-and-drop, mouse hover, and keyboard events, boosting test coverage and accuracy.


Actions Class Overview

  1. What is the primary purpose of the Selenium Actions class?
    a) To interact with browser settings
    b) To automate mouse and keyboard actions
    c) To manage web element locators
    d) To execute JavaScript
  2. Which method initializes the Actions class in Selenium?
    a) Actions action = new Actions();
    b) Actions action = new Actions(driver);
    c) action.start(driver);
    d) action.create(driver);
  3. What does the perform() method do in the Actions class?
    a) Executes the stored actions
    b) Clears previous actions
    c) Starts new actions
    d) Ends the current action
  4. Which is NOT a method in the Actions class?
    a) clickAndHold()
    b) release()
    c) dragAndDrop()
    d) scrollTo()
  5. The Actions class is part of which Selenium package?
    a) org.openqa.selenium.actions
    b) org.openqa.selenium.interactions
    c) org.openqa.selenium.mouse
    d) org.openqa.selenium.tools

Drag and Drop, Mouse Hover

  1. What is the purpose of dragAndDrop() in Selenium?
    a) Moves an element to a target location
    b) Highlights an element
    c) Selects a text element
    d) Clicks an element
  2. Which method is used for mouse hover in Selenium?
    a) moveByOffset()
    b) moveToElement()
    c) hoverElement()
    d) scrollToElement()
  3. How do you perform a drag-and-drop action in Selenium?
    a) action.dragAndDrop(source, target).perform();
    b) action.drag(source).drop(target).perform();
    c) action.move(source).click(target).perform();
    d) action.moveTo(source, target).perform();
  4. What is the alternate method for dragAndDrop()?
    a) clickAndHold().moveToElement().release().perform()
    b) select().move().release()
    c) drag().drop().perform()
    d) click().move().drop()
  5. Which method allows specifying offset positions for mouse movements?
    a) moveByOffset(x, y)
    b) dragAndDropBy(x, y)
    c) scrollByOffset(x, y)
    d) moveToOffset(x, y)
  6. What is the prerequisite for performing mouse hover actions in Selenium?
    a) The element must be visible
    b) The element must be draggable
    c) The element must have an ID
    d) The element must be selectable
  7. Which method selects multiple elements by holding down the mouse?
    a) clickAndHold()
    b) release()
    c) selectMultiple()
    d) dragMultiple()
  8. When using dragAndDropBy(), what do the x and y parameters specify?
    a) The number of pixels to drag
    b) The coordinates of the target element
    c) The width and height of the element
    d) The duration of the drag action
  9. How can you simulate a right-click using the Actions class?
    a) contextClick()
    b) rightClick()
    c) clickRight()
    d) doubleClick()
  10. What does the moveToElement() method do?
    a) Moves the mouse cursor to the specified element
    b) Scrolls to the specified element
    c) Drags the element to a new location
    d) Clicks the element

Keyboard Events (KeyPress, KeyRelease)

  1. What method simulates pressing a keyboard key in Selenium?
    a) keyDown()
    b) pressKey()
    c) sendKey()
    d) simulateKey()
  2. Which method simulates releasing a keyboard key in Selenium?
    a) keyUp()
    b) releaseKey()
    c) stopKey()
    d) clearKey()
  3. What parameter does sendKeys() accept?
    a) A sequence of characters or keys
    b) A key object only
    c) An element selector
    d) A boolean value
  4. How do you simulate holding down the Shift key while entering text?
    a) keyDown(Keys.SHIFT).sendKeys("text").keyUp(Keys.SHIFT).perform();
    b) press(Keys.SHIFT).sendKeys("text").release(Keys.SHIFT).perform();
    c) shiftDown().sendKeys("text").shiftUp().perform();
    d) sendKeys(Keys.SHIFT, "text").perform();
  5. Which method sends a keyboard shortcut (e.g., Ctrl+C) in Selenium?
    a) keyDown(Keys.CONTROL).sendKeys("C").keyUp(Keys.CONTROL).perform();
    b) sendShortcut(Keys.CONTROL, "C").perform();
    c) sendKeys(Keys.CONTROL, "C").perform();
    d) keyPress(Keys.CONTROL, "C").perform();
  6. What is the purpose of sendKeys(Keys.TAB)?
    a) Simulates a tab key press for navigation
    b) Switches to a new tab
    c) Opens the tab settings
    d) Moves to the next element
  7. How can you simulate a backspace key press in Selenium?
    a) sendKeys(Keys.BACKSPACE)
    b) keyDown(Keys.DELETE)
    c) keyPress(Keys.REMOVE)
    d) removeKey(Keys.BACKSPACE)
  8. Which key combination is used for selecting all text (e.g., Ctrl+A)?
    a) keyDown(Keys.CONTROL).sendKeys("A").keyUp(Keys.CONTROL).perform();
    b) sendKeys(Keys.CONTROL + "A").perform();
    c) sendShortcut("Ctrl", "A").perform();
    d) press(Keys.CONTROL + "A").perform();
  9. How do you simulate pressing the Enter key in Selenium?
    a) sendKeys(Keys.ENTER)
    b) keyDown(Keys.RETURN)
    c) keyPress(Keys.ENTER)
    d) pressKey(Keys.SUBMIT)
  10. What does the keyDown(Keys.CONTROL) method do?
    a) Simulates holding down the Ctrl key
    b) Sends a Ctrl key press
    c) Simulates releasing the Ctrl key
    d) Executes a browser shortcut
  11. What method is used to simulate releasing the Shift key?
    a) keyUp(Keys.SHIFT)
    b) releaseKey(Keys.SHIFT)
    c) stopShift(Keys.SHIFT)
    d) shiftRelease(Keys.SHIFT)
  12. How do you send a combination of multiple keys in Selenium?
    a) keyDown(Keys).sendKeys().keyUp(Keys).perform()
    b) combineKeys(Keys).perform()
    c) sendKeys(Keys.COMBINE).perform()
    d) multiKeySend(Keys).perform()
  13. Which method allows typing text into an input field in Selenium?
    a) sendKeys("text")
    b) type("text")
    c) enterText("text")
    d) insertText("text")
  14. How can you simulate pressing the spacebar key?
    a) sendKeys(Keys.SPACE)
    b) keyPress(Keys.BLANK)
    c) sendKeys(Keys.BLANK)
    d) pressKey(Keys.SPACE)
  15. Which method clears the focus from a text input field in Selenium?
    a) sendKeys(Keys.TAB)
    b) keyPress(Keys.ESC)
    c) clearFocus()
    d) sendKeys(Keys.RELEASE)

Keyboard and Mouse Actions in Selenium:

QNoAnswer (Option with the text)
1b) To automate mouse and keyboard actions
2b) Actions action = new Actions(driver);
3a) Executes the stored actions
4d) scrollTo()
5b) org.openqa.selenium.interactions
6a) Moves an element to a target location
7b) moveToElement()
8a) action.dragAndDrop(source, target).perform();
9a) clickAndHold().moveToElement().release().perform()
10a) moveByOffset(x, y)
11a) The element must be visible
12a) clickAndHold()
13a) The number of pixels to drag
14a) contextClick()
15a) Moves the mouse cursor to the specified element
16a) keyDown()
17a) keyUp()
18a) A sequence of characters or keys
19a) keyDown(Keys.SHIFT).sendKeys("text").keyUp(Keys.SHIFT).perform();
20a) keyDown(Keys.CONTROL).sendKeys("C").keyUp(Keys.CONTROL).perform();
21a) Simulates a tab key press for navigation
22a) sendKeys(Keys.BACKSPACE)
23a) keyDown(Keys.CONTROL).sendKeys("A").keyUp(Keys.CONTROL).perform();
24a) sendKeys(Keys.ENTER)
25a) Simulates holding down the Ctrl key
26a) keyUp(Keys.SHIFT)
27a) keyDown(Keys).sendKeys().keyUp(Keys).perform()
28a) sendKeys("text")
29a) sendKeys(Keys.SPACE)
30a) sendKeys(Keys.TAB)

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