Hovering over a link in nightwatchjs

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 02:38:19

问题


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


回答1:


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




回答2:


You can use the selenium API moveTo command. It will move the mouse to the given element and it should stay over that element until the next command involving the mouse is used.

browser.moveTo(selector, xoffset, yoffset, function(){
    browser.pause(2000)
})

Just pause for the amount of time you would like to hover for. Here is the api documentation for moveTo.



来源:https://stackoverflow.com/questions/30673307/hovering-over-a-link-in-nightwatchjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!