Learn Selenium
上QQ阅读APP看书,第一时间看更新

The double click at current location action

 Moving on to another action that can be performed using a mouse, doubleClick() is another out- of-the-box method that WebDriver provides to emulate the double-clicking of the mouse. This method, like the click() method, comes in two flavors. One is double-clicking a WebElement, which we will discuss in next section; the second is clicking at the current location of the cursor, which will be discussed here.

The API syntax is as follows:

public Actions doubleClick()

Obviously, the preceding method doesn't take any input parameters, as it just clicks on the current cursor location and returns an actions class instance. Let's see how the previous code can be converted to use this method:

@Test
public void shouldDoubleClick() {

driver.get("http://guidebook.seleniumacademy.com/DoubleClick.html");

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

In the preceding code, we have used the moveToElement(WebElement) method to move the mouse to the location of the button element and just double-clicked at the current location. Here is the output after performing the double-click on the element on the sample page: