Bird
0
0

Which of the following code snippets correctly performs this and asserts the message is displayed?

hard📝 Application Q15 of 15
Selenium Java - Actions Class
You want to double click on a button with id submitBtn and then verify if a confirmation message with id confirmMsg appears. Which of the following code snippets correctly performs this and asserts the message is displayed?
AWebElement btn = driver.findElement(By.id("submitBtn")); new Actions(driver).click(btn).click(btn).perform(); assertTrue(driver.findElement(By.id("confirmMsg")).isDisplayed());
BWebElement btn = driver.findElement(By.id("submitBtn")); new Actions(driver).doubleClick(btn).perform(); WebElement msg = driver.findElement(By.id("confirmMsg")); assertTrue(msg.isDisplayed());
CActions action = new Actions(driver); action.doubleClick(); action.perform(); assertTrue(driver.findElement(By.id("confirmMsg")).isDisplayed());
Ddriver.findElement(By.id("submitBtn")).doubleClick(); assertTrue(driver.findElement(By.id("confirmMsg")).isDisplayed());
Step-by-Step Solution
Solution:
  1. Step 1: Perform double click on the button element

    WebElement btn = driver.findElement(By.id("submitBtn")); new Actions(driver).doubleClick(btn).perform(); WebElement msg = driver.findElement(By.id("confirmMsg")); assertTrue(msg.isDisplayed()); correctly finds the button element and uses new Actions(driver).doubleClick(btn).perform(); to double click it.
  2. Step 2: Verify confirmation message is displayed

    WebElement btn = driver.findElement(By.id("submitBtn")); new Actions(driver).doubleClick(btn).perform(); WebElement msg = driver.findElement(By.id("confirmMsg")); assertTrue(msg.isDisplayed()); then finds the confirmation message element and asserts it is displayed using assertTrue(msg.isDisplayed());.
  3. Final Answer:

    Correct double click and assertion sequence -> Option B
  4. Quick Check:

    Find element + doubleClick + assert displayed = correct [OK]
Quick Trick: Use Actions with element, then assert message visibility [OK]
Common Mistakes:
  • Using click twice instead of doubleClick()
  • Calling doubleClick() without element
  • Trying to doubleClick() directly on driver

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes