Bird
0
0

You need to double click a button only if it is both visible and enabled. Which of the following code snippets correctly implements this check before performing the double click?

hard📝 Application Q8 of 15
Selenium Java - Actions Class
You need to double click a button only if it is both visible and enabled. Which of the following code snippets correctly implements this check before performing the double click?
AWebElement btn = driver.findElement(By.id("btn")); new Actions(driver).doubleClick(btn).perform();
BWebElement btn = driver.findElement(By.id("btn")); if(btn.isDisplayed() && btn.isEnabled()) { new Actions(driver).doubleClick(btn).perform(); }
CWebElement btn = driver.findElement(By.id("btn")); if(btn.isEnabled()) { new Actions(driver).doubleClick(btn).perform(); }
DWebElement btn = driver.findElement(By.id("btn")); if(btn.isDisplayed()) { new Actions(driver).doubleClick(btn).perform(); }
Step-by-Step Solution
Solution:
  1. Step 1: Check visibility and enabled state

    Use isDisplayed() and isEnabled() to verify the button is interactable.
  2. Step 2: Perform double click only if both true

    Wrap the doubleClick action inside the if condition checking both.
  3. Step 3: Execute action

    Call perform() to execute the double click.
  4. Final Answer:

    WebElement btn = driver.findElement(By.id("btn")); if(btn.isDisplayed() && btn.isEnabled()) { new Actions(driver).doubleClick(btn).perform(); } correctly checks both conditions before double clicking.
  5. Quick Check:

    Check visibility and enabled before actions. [OK]
Quick Trick: Check isDisplayed() and isEnabled() before doubleClick [OK]
Common Mistakes:
MISTAKES
  • Skipping visibility or enabled checks
  • Calling doubleClick without perform()
  • Checking only one condition instead of both

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes