CasperJS: How to Wait between each Mouse Move?

359
August 18, 2017, at 02:57 AM

I have a CasperJS script that move the mouse over all elements with a certain class. When the mouse is over the element, a new div (acting as a tooltip appear) with the tooltip data updated via javascript. When I move over another element, the tooltip data change. There are over 60 elements on the page and I need to get the exact data of all these tooltips. I come up with a script that almost work.

However, since happen so quickly the data extracted from the tool is sometime wrong. I tried adding a subjective small delay (100) but this wont work if there is load delay etc. How can I make sure that the data is extracted correctly between each mouse move?

Here what I have so far:

var count = casper.getElementsInfo('.myClass').length;
var counter = 1;
for (var i = 0; i < count; i++) {
casper.then(function () {
  casper.mouse.move('.myClass:nth-of-type('+counter+')');
  casper.wait(100);
  var data = casper.getElementInfo('.tooltipClass').text;
  this.echo(data);
  counter ++;
})
} 
Answer 1

you might want to take a look at the Casperjs waitFor function and use it to wait until the tooltip you need appears and then click on it

http://docs.casperjs.org/en/latest/modules/casper.html#waitfor

READ ALSO
How to iterate js function?

How to iterate js function?

I have some repeat button control functions as below, is there a way to iterate them and reduce amount of code?

366
How do I host Microsoft Sql server in Amazon aws server??

How do I host Microsoft Sql server in Amazon aws server??

I have created a simple windows form application with databaseI want to use the exe file of my application in different places but I want to store all the data into a centralized database

257
How to display Json data using checkboxes in my jsp page? [on hold]

How to display Json data using checkboxes in my jsp page? [on hold]

I'm getting the JSON data from the server as a string and parsing it using JSONparse()

265