Bird
0
0

What will be the output of the following code snippet if the element is hidden?

medium📝 Predict Output Q13 of 15
Selenium Java - JavaScriptExecutor
What will be the output of the following code snippet if the element is hidden?
WebElement element = driver.findElement(By.id("hiddenBtn"));
boolean visible = element.isDisplayed();
System.out.println(visible);
Afalse
Btrue
Cnull
DThrows NoSuchElementException
Step-by-Step Solution
Solution:
  1. Step 1: Understand isDisplayed() behavior

    The isDisplayed() method returns false if the element exists but is hidden (not visible).
  2. Step 2: Check element presence

    Since findElement finds the element by id, no exception is thrown. The element is hidden, so isDisplayed() returns false.
  3. Final Answer:

    false -> Option A
  4. Quick Check:

    Hidden element visibility = false [OK]
Quick Trick: isDisplayed() returns false for hidden elements [OK]
Common Mistakes:
  • Assuming isDisplayed() throws exception if element is hidden
  • Confusing false with null
  • Expecting true without checking visibility

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes