Bird
0
0

What is the issue with this Selenium Java code snippet that attempts to click a hidden button?

medium📝 Debug Q6 of 15
Selenium Java - JavaScriptExecutor
What is the issue with this Selenium Java code snippet that attempts to click a hidden button?
WebElement btn = driver.findElement(By.id("btnHidden"));
btn.click();
AThe element locator is incorrect
Bclick() cannot interact with hidden elements, causing ElementNotInteractableException
CNo error; the click will succeed
DThe element is stale and needs to be refreshed
Step-by-Step Solution
Solution:
  1. Step 1: Understand click() limitations

    click() fails on hidden elements, throwing ElementNotInteractableException.
  2. Step 2: Check locator and element state

    Assuming locator is correct and element is not stale.
  3. Final Answer:

    click() cannot interact with hidden elements, causing ElementNotInteractableException -> Option B
  4. Quick Check:

    click() fails on hidden elements [OK]
Quick Trick: click() throws exception if element is hidden [OK]
Common Mistakes:
MISTAKES
  • Assuming click() works on hidden elements
  • Blaming locator without verification
  • Ignoring ElementNotInteractableException

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes