The double click on WebElement action

Now that we have seen a method that double-clicks at the current location, we will discuss another method that WebDriver provides to emulate the double-clicking of a WebElement.

The API syntax for the doubleClick() method is as follows:

public Actions doubleClick(WebElement onElement)

The input parameter for the preceding method is the target WebElement that has to be double-clicked, and the return type is the Actions class.

Let's see a code example for this. Open the DoubleClick.html file and single-click on the Click Me button. You shouldn't see anything happening. Now double-click on the button; you should see an alert saying Double Clicked !!. Now we will try to do the same thing using WebDriver. The following is the code to do that:

@Test
public void shouldDoubleClickElement() {
driver.get("http://guidebook.seleniumacademy.com/DoubleClick.html");

WebElement dblClick = driver.findElement(By.name("dblClick"));
Actions actions = new Actions(driver);
actions.doubleClick(dblClick).perform();
}

After executing the preceding code, you should see an alert dialog saying that the button has been double-clicked.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.70.93