Skip to content

Instantly share code, notes, and snippets.

@umaar
Created February 17, 2014 14:05
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save umaar/9051143 to your computer and use it in GitHub Desktop.
Save umaar/9051143 to your computer and use it in GitHub Desktop.
Hover over an element in WebDriverJS
/*
* Hover over an element on the page
*/
(function() {
"use strict";
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome' }).build();
driver.manage().window().setSize(1280, 1000).then(function() {
driver.get('http://www.shazam.com/discover/track/58858793');
driver.findElement(webdriver.By.css('.ta-tracks li:first-child')).then(function(elem){
driver.actions().mouseMove(elem).perform();
driver.sleep(5000);
driver.quit();
});
});
}());
@pgupt
Copy link

pgupt commented Jul 7, 2020

You can use this code for mouse hover in selenium javascript:-
const actions = driver.actions({bridge: true}); var elem=await driver.findElement(By.id("myId")); await actions.move({duration:5000,origin:elem,x:0,y:0}).perform();

This code has to be inside an async function as await is used, or else to use with promise, this code might help:-

const actions = driver.actions({bridge: true}); driver.findElement(By.id("myId")).then((elem)=>{ actions.move({duration:5000,origin:elem,x:0,y:0}).perform(); });
hope it helps....

This works. Thanks.

@ghou1337
Copy link

ghou1337 commented Aug 4, 2022

<3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment