Test Overview
This test opens a webpage, finds a button, performs a double click on it, and verifies that the double click action triggered the expected change.
This test opens a webpage, finds a button, performs a double click on it, and verifies that the double click action triggered the expected change.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class DoubleClickTest { WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); } @Test public void testDoubleClick() { driver.get("https://example.com/double-click-test"); WebElement button = driver.findElement(By.id("double-click-btn")); Actions actions = new Actions(driver); actions.doubleClick(button).perform(); WebElement message = driver.findElement(By.id("message")); String text = message.getText(); assertEquals("Double click successful", text); } @AfterEach public void tearDown() { driver.quit(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open with a blank page | — | PASS |
| 2 | Navigates to URL https://example.com/double-click-test | Page loads showing a button with id 'double-click-btn' and a message area with id 'message' | — | PASS |
| 3 | Finds the button element by id 'double-click-btn' | Button element is located and ready for interaction | — | PASS |
| 4 | Performs double click action on the button using Actions.doubleClick().perform() | Button receives double click event, triggering page logic | — | PASS |
| 5 | Finds the message element by id 'message' to verify result | Message element is located and contains updated text | Check that message text equals 'Double click successful' | PASS |
| 6 | Assertion verifies the message text is exactly 'Double click successful' | Text matches expected result | assertEquals("Double click successful", text) | PASS |
| 7 | Test ends and browser closes | Browser window is closed | — | PASS |
doubleClick() method in Selenium WebDriver's Actions class?Actions class roleActions class in Selenium is used to build complex user interactions like mouse and keyboard events.doubleClick() method functiondoubleClick() method specifically performs a double-click on the targeted web element.Actions object with the driver, then chain the doubleClick() method with the target element, and call perform() to execute.new Actions(driver).doubleClick(element).perform();. Others are invalid or incorrect method calls.WebElement element = driver.findElement(By.id("btn"));
new Actions(driver).doubleClick(element).perform();
System.out.println("Double click performed");doubleClick() will execute without exceptions.Actions action = new Actions(driver); action.doubleClick(); action.perform();
doubleClick() method requires a target WebElement to act on. Calling it without an element is incorrect.perform() after building the action is correct. The method exists and Actions object need not be static.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?new Actions(driver).doubleClick(btn).perform(); to double click it.assertTrue(msg.isDisplayed());.Pass the test and this pattern moves unknown