Created
February 17, 2014 14:05
-
-
Save umaar/9051143 to your computer and use it in GitHub Desktop.
Hover over an element in WebDriverJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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(); | |
}); | |
}); | |
}()); |
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.
<3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works amazingly well in Chrome! Thanks for the help.