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

Move mouse to trigger a hover event in CasperJS

本文关键字:悬停 事件 CasperJS 鼠标 移动      更新时间:2023-09-26

我不明白mouse::move()为什么不工作。例如,在此页面上。

正如你所看到的,有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 }
});