Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
Selenium Java - Actions Class
What is wrong with this code?
WebElement element = driver.findElement(By.id("btn"));
Actions actions = new Actions(driver);
actions.contextClick(element).build();
AActions object must be created after build()
BcontextClick cannot take element as argument
CMissing perform() call after build()
Dbuild() should be called before contextClick()
Step-by-Step Solution
Solution:
  1. Step 1: Understand build() vs perform()

    The build() method creates the composite action but does not execute it. perform() must be called to run the action.
  2. Step 2: Identify missing perform()

    The code calls build() but never calls perform(), so the right-click will not happen.
  3. Final Answer:

    Missing perform() call after build() -> Option C
  4. Quick Check:

    build() creates action; perform() executes it [OK]
Quick Trick: Always call perform() to execute built actions [OK]
Common Mistakes:
MISTAKES
  • Calling build() without perform()
  • Thinking build() runs the action
  • Misusing contextClick argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes