Bird
0
0

Consider the following code snippet:

medium📝 Predict Output Q13 of 15
Selenium Java - Actions Class
Consider the following code snippet:
WebElement menu = driver.findElement(By.id("menu"));
Actions actions = new Actions(driver);
actions.moveToElement(menu).perform();
String tooltip = driver.findElement(By.id("tooltip")).getText();
System.out.println(tooltip);

What will be printed if the tooltip appears only after mouse hover?
AEmpty string is printed
BThe tooltip text is printed
CNoSuchElementException is thrown
DStaleElementReferenceException is thrown
Step-by-Step Solution
Solution:
  1. Step 1: Understand the hover effect

    The moveToElement(menu).perform() simulates mouse hover on the menu element, which triggers the tooltip to appear.
  2. Step 2: Check tooltip retrieval

    After hover, the code finds the tooltip element by id and gets its text. Since the tooltip appears on hover, the text will be present and printed.
  3. Final Answer:

    The tooltip text is printed -> Option B
  4. Quick Check:

    Hover triggers tooltip, so text prints [OK]
Quick Trick: Hover first, then get tooltip text to see it [OK]
Common Mistakes:
MISTAKES
  • Assuming tooltip is present before hover
  • Not calling perform() after moveToElement()
  • Expecting exceptions without missing elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes