Bird
0
0

Consider the code:

medium📝 Predict Output Q4 of 15
Selenium Java - JavaScriptExecutor
Consider the code:
WebElement elem = driver.findElement(By.id("hiddenBtn"));
boolean isVisible = elem.isDisplayed();
System.out.println(isVisible);

If the element with id "hiddenBtn" is not visible on the page, what will be the output?
Atrue
Bfalse
Cnull
DThrows NoSuchElementException
Step-by-Step Solution
Solution:
  1. Step 1: Locate element

    driver.findElement finds element even if hidden (present in DOM).
  2. Step 2: Check visibility

    isDisplayed() returns false if element is hidden.
  3. Step 3: Output

    System.out.println prints false.
  4. Final Answer:

    false -> Option B
  5. Quick Check:

    Hidden element's isDisplayed() returns false [OK]
Quick Trick: isDisplayed() returns false for hidden elements [OK]
Common Mistakes:
  • Assuming isDisplayed() throws exception if hidden
  • Expecting true output for hidden elements
  • Confusing NoSuchElementException with hidden element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes