Mouse Interactions

Learn how to perform mouse actions using Selenium.

Double click a control

We can double click on a control by:

Press + to interact
driver.get("file://" + __dirname + "/../../site/text_field.html");
var elem = driver.findElement(By.id("quickfill"));
driver.actions()
.doubleClick(elem)
.perform();
driver.findElement(By.id("pass")).getAttribute("value").then(function(pwd_value) {
assert.equal("ABC", pwd_value);
})

Move the mouse to a control - Mouse Over

We can pair the mouse pointer with the desired element by:

Press + to interact
var elem = driver.findElement(By.id("email"));
driver.actions()
.mouseMove(elem)
.perform();

Click and hold - select multiple items

The test scripts below ...

...

Press + to interact
driver.get("http://jqueryui.com/selectable");
driver.findElement(By.linkText("Display as grid")).click().then(function() {
driver.sleep(2000);
driver.switchTo().frame(0);
driver.findElements(By.xpath("//ol[@id='selectable']/li")).then(function(lis){
driver.actions()
.mouseMove(lis[1])
.mouseDown()
.mouseMove(lis[3])
.mouseUp()
.perform();
driver.switchTo().defaultContent();
});
});
...