Bird
0
0

You want to perform a right-click (context click) on an element and then select an option from the context menu using Selenium Java. Which approach correctly uses the Actions API to achieve this?

hard📝 Application Q15 of 15
Selenium Java - Actions Class
You want to perform a right-click (context click) on an element and then select an option from the context menu using Selenium Java. Which approach correctly uses the Actions API to achieve this?
AUse <code>action.doubleClick(element).perform();</code> then <code>driver.findElement(...).click();</code>
BUse <code>element.rightClick();</code> followed by <code>driver.findElement(...).click();</code>
CUse <code>action.click(element).perform();</code> then <code>driver.findElement(...).click();</code>
DUse <code>action.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).perform();</code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct Actions API method for right-click

    The method contextClick(element) performs a right-click on the element.
  2. Step 2: Chain keyboard actions to select menu option

    Sending arrow down and enter keys simulates selecting an option from the context menu.
  3. Step 3: Execute all actions with perform()

    Calling perform() runs the chained actions in order.
  4. Final Answer:

    Use action.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).perform(); -> Option D
  5. Quick Check:

    Right-click + keyboard keys + perform() = Use action.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).perform(); [OK]
Quick Trick: Chain contextClick with keys and perform() [OK]
Common Mistakes:
  • Using non-existent rightClick() method on element
  • Using click instead of contextClick
  • Forgetting to call perform()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes