Bird
0
0

Which of the following code snippets correctly performs this action on three elements: elem1, elem2, and elem3?

hard📝 Application Q8 of 15
Selenium Java - Actions Class
You want to select multiple items in a list by holding the CONTROL key and clicking each item. Which of the following code snippets correctly performs this action on three elements: elem1, elem2, and elem3?
Aactions.keyDown(Keys.CONTROL).click(elem1).keyUp(Keys.CONTROL).click(elem2).click(elem3).perform();
Bactions.click(elem1).keyDown(Keys.CONTROL).click(elem2).click(elem3).keyUp(Keys.CONTROL).perform();
Cactions.keyDown(Keys.CONTROL).click(elem1).click(elem2).click(elem3).keyUp(Keys.CONTROL).perform();
Dactions.click(elem1).click(elem2).click(elem3).keyDown(Keys.CONTROL).keyUp(Keys.CONTROL).perform();
Step-by-Step Solution
Solution:
  1. Step 1: Hold CONTROL key before clicking all elements

    Use keyDown(Keys.CONTROL) before clicking elem1, elem2, and elem3.
  2. Step 2: Release CONTROL key after all clicks

    Call keyUp(Keys.CONTROL) after clicking all elements, then perform the action.
  3. Final Answer:

    actions.keyDown(Keys.CONTROL).click(elem1).click(elem2).click(elem3).keyUp(Keys.CONTROL).perform(); -> Option C
  4. Quick Check:

    Hold CONTROL, click all, release CONTROL = C [OK]
Quick Trick: Hold keyDown before all clicks, release after last click [OK]
Common Mistakes:
MISTAKES
  • Releasing CONTROL too early
  • Starting clicks before keyDown
  • Calling perform() too soon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes