移动鼠标触发 CasperJS 中的悬停事件

Move mouse to trigger a hover event in CasperJS

我不明白,为什么 mouse::move() 不起作用。例如 this page.

如您所见,共有10个元素,将鼠标光标移动到每张图片后,您将看到详细信息。我有一组每个元素 id。我想在每个元素上移动光标,然后选择器 "div#hover_item_descriptors" 将被更新,我将使用它。这是我的代码:

this.eachThen(ids, function(resp){
  var id = resp.data;

  this.then(function(){
    this.mouse.move('span#' + id + '_name'); //moving at the name of element
  });

  this.waitUntilVisible('div#hover_item_descriptors div#sticker_info', function(){
    // it`s never work, because moving doesn't work
  });
});

为什么不起作用?

我也偶然发现了这个问题,多亏了这个问题才弄明白:https://github.com/n1k0/casperjs/issues/208

事实证明,如果您将光标悬停在不在视口中的元素上,悬停事件将不起作用。

因此,要使其正常工作,请设置保证超过页面高度的视口高度,例如:

var casper = require('casper').create({
    viewportSize : { width: 1280, height: 5000 }
});