Bird
0
0

Consider this code:

medium📝 Predict Output Q5 of 15
Selenium Java - JavaScriptExecutor
Consider this code:
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement link = driver.findElement(By.cssSelector("a.hidden-link"));
js.executeScript("arguments[0].click();", link);

What is the expected result if the link is hidden by CSS?
AA StaleElementReferenceException will be thrown
BThe link will be clicked successfully despite being hidden
CNo click will happen because the link is not visible
DA JavaScript error will occur due to hidden element
Step-by-Step Solution
Solution:
  1. Step 1: Understand JavaScript click behavior on hidden elements

    JavaScript click triggers the click event directly on the element regardless of CSS visibility.
  2. Step 2: Confirm no exceptions expected

    Since the element is found and valid, no exceptions or JS errors occur.
  3. Final Answer:

    The link will be clicked successfully despite being hidden -> Option B
  4. Quick Check:

    JS click ignores visibility = C [OK]
Quick Trick: JS click works even if element is hidden by CSS [OK]
Common Mistakes:
  • Assuming hidden elements cannot be clicked
  • Expecting exceptions on hidden elements
  • Confusing visibility with interactability

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes