Hovering over a link in nightwatchjs

user461112 picture user461112 · Jun 5, 2015 · Viewed 10k times · Source

I have been using nightwatch.js and always clicked around elements. Is there a way we can hover over a link or button?

Answer

Abhishek picture Abhishek · Jun 15, 2015

Try the browser.moveToElement command.

You can also fire a callback after moveToElement completes:

browser.waitForElementVisible('.recommendation', 1000, function () {
// moveToElement can also accept offsets
browser.moveToElement('.recommendation', 100, 100, function() {
    browser.waitForElementVisible('.share', 500, function () {
        browser.click('.share');
    }, "Click share icon. ");
});
}, "Find a recommendation ");

The code above moves to an element. After the moveTo completes it waits until the hover-only element is present. After which it interacts with it.

doc: http://nightwatchjs.org/api/moveToElement.html