I'm just used to PhantomJs, and still its really cool.
I am trying to crawl a site and get product data on the site. Each product page displays the default product color. When you click on a color swatch, it changes the new color, launching the function. Each clickable color swatch element is as follows:
<input type="image" id="swatch_0" onclick="pPage.getColor(0);" src="http://www.site.com/img50067.jpg">
getColor updates the thumbnail and price for this color. The identifier is incremented for each available color (swatch_0, swatch_1, etc.), and the argument is also passed the getColor increment. I want to iterate over each color using PhantomJs and retrieve the corresponding data for each.
I loaded the page, loaded jQuery and was able to pull out the data for the color loaded in the initial color, but nothing allows me to execute click events.
here is what i am trying:
page.evalaute(function){ var selection = $('#confirmText').text(); // name of the color var price = $('#priceText').text(); // price for that color console.log('Price is: ' + price); console.log('Selection is: ' + selection); console.log($('#swatch_1')); $('#swatch_1').trigger("click"); selection = $('#selectionConfirmText').text(); price = $('#priceText').text(); console.log('Price is: ' + price); console.log('Selection is: ' + selection); }
This gives me:
console> Price is: $19.95 console> Selection is: blue console> [Object Object] console> TypeError: 'undefined' is not and object // repeating until I manually exit
other code does not run. I also tried to fire the event without jQuery as follows:
var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); var cb = document.getElementById("swatch_1"); cb.dispatchEvent(evt);
And by running the function directly:
pPage.getColor(1);
And I get the same result. Any help is appreciated.