Saturday, August 24, 2024

Actions Using Selenium Java MCQ

 MCQs on Actions Using Selenium Java

Which class in Selenium is used for performing complex user interactions such as mouse and keyboard actions?


a) WebElement

b) Action

c) Actions

d) Interactions

Answer: c) Actions


What is the correct way to initialize the Actions class in Selenium Java?


a) Actions actions = new Actions(driver);

b) Actions action = new Actions();

c) Actions actions = new Action(driver);

d) Action actions = new Actions(driver);

Answer: a) Actions actions = new Actions(driver);


Which method is used to perform a right-click action on a web element using the Actions class?


a) actions.contextClick()

b) actions.rightClick()

c) actions.click()

d) actions.doubleClick()

Answer: a) actions.contextClick()


How do you perform a double-click action on an element using the Actions class?


a) actions.doubleClick(element).perform();

b) actions.clickTwice(element).perform();

c) actions.doubleClick().perform();

d) actions.click(element).perform();

Answer: a) actions.doubleClick(element).perform();


Which method is used to click and hold a web element using the Actions class?


a) clickAndHold(element)

b) holdClick(element)

c) clickHold(element)

d) holdClickAndDrag(element)

Answer: a) clickAndHold(element)


What is the purpose of the build() method in the Actions class?


a) To execute multiple actions

b) To combine multiple actions into a single action

c) To build the Actions class object

d) To reset the actions sequence

Answer: b) To combine multiple actions into a single action


How do you drag and drop an element from one location to another using the Actions class?


a) actions.dragAndDrop(source, target).perform();

b) actions.dragDrop(source, target).perform();

c) actions.moveTo(source).moveTo(target).release().perform();

d) actions.clickAndHold(source).moveToElement(target).release().perform();

Answer: a) actions.dragAndDrop(source, target).perform();


Which method moves the mouse to the middle of the specified element?


a) moveToElement(element)

b) hoverOverElement(element)

c) moveToMiddle(element)

d) hoverToElement(element)

Answer: a) moveToElement(element)


How do you perform a series of actions like click, hold, and release in Selenium?


a) actions.click().hold().release().perform();

b) actions.clickAndHold().moveByOffset(10, 10).release().perform();

c) actions.sequenceClickHoldRelease().perform();

d) actions.pressAndRelease().perform();

Answer: b) actions.clickAndHold().moveByOffset(10, 10).release().perform();


Which method is used to perform a keyboard key press using the Actions class?


a) sendKeys(Keys.KEY)

b) keyDown(Keys.KEY)

c) pressKey(Keys.KEY)

d) keyPress(Keys.KEY)

Answer: b) keyDown(Keys.KEY)


How do you release a key that was pressed down using the Actions class?


a) keyRelease(Keys.KEY)

b) releaseKey(Keys.KEY)

c) keyUp(Keys.KEY)

d) release(Keys.KEY)

Answer: c) keyUp(Keys.KEY)


Which method is used to move the mouse to an offset from the current location?


a) moveByOffset(x, y)

b) moveToOffset(x, y)

c) mouseMove(x, y)

d) moveOffset(x, y)

Answer: a) moveByOffset(x, y)


Which method in the Actions class is used to perform all actions that are queued?


a) execute()

b) perform()

c) run()

d) commit()

Answer: b) perform()


Which exception might be thrown if the perform() method is called on a sequence of actions that includes a move to an element that is not interactable?


a) ElementNotInteractableException

b) ActionNotCompletedException

c) ElementNotVisibleException

d) InvalidActionException

Answer: a) ElementNotInteractableException


What does the sendKeys() method in the Actions class do?


a) Sends keyboard input to the currently focused element

b) Simulates typing keys on the keyboard

c) Performs key up and key down actions

d) Sends keys directly to a specified element

Answer: b) Simulates typing keys on the keyboard


How do you perform a click-and-hold action on a web element using the Actions class?


a) clickAndHold(element)

b) clickHold(element)

c) holdClick(element)

d) clickAndDrag(element)

Answer: a) clickAndHold(element)


What method would you use to hover over an element and display a dropdown menu using the Actions class?


a) hoverOverElement(element)

b) moveToElement(element)

c) clickAndHold(element)

d) hoverAndShow(element)

Answer: b) moveToElement(element)


To perform a keyboard shortcut (e.g., Ctrl + A), which Actions method combination is correct?


a) keyDown(Keys.CONTROL).sendKeys("A").keyUp(Keys.CONTROL).perform();

b) pressKey(Keys.CONTROL + "A").perform();

c) sendKeys(Keys.CONTROL, "A").perform();

d) shortcut(Keys.CONTROL, "A").perform();

Answer: a) keyDown(Keys.CONTROL).sendKeys("A").keyUp(Keys.CONTROL).perform();


Which method combination would you use to click and drag an element to a target location using the Actions class?


a) clickAndHold(element).moveToElement(target).release().perform();

b) clickAndHold(element).dragTo(target).release().perform();

c) dragAndDrop(element, target).perform();

d) moveElementTo(element, target).perform();

Answer: a) clickAndHold(element).moveToElement(target).release().perform();


Which method in the Actions class would you use to perform a sequence of keyboard and mouse actions?


a) sendKeysAndClick()

b) performSequence()

c) build()

d) keyAndMouseSequence()

Answer: c) build()

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