Note that there are some explanatory texts on larger screens.

plurals
  1. POPhantomJs clicking links or running on-page functions
    primarykey
    data
    text
    <p>I'm just getting used to PhantomJs and so far its really cool. </p> <p>I'm trying to crawl a site and get data about the products on the site. Each product page loads with the default color of the product visible. When you click on a color swatch it swaps the new color out by running a function. Each clickable color swatch element looks like this: </p> <pre><code>&lt;input type="image" id="swatch_0" onclick="pPage.getColor(0);" src="http://www.site.com/img50067.jpg"&gt; </code></pre> <p>getColor updates the thumbnail and price for that color. The id increments for each available color (swatch_0, swatch_1, etc) and the argument passed to getColor increments as well. I want to iterate through each color with PhantomJs and pull the relevant data for each. </p> <p>I've loaded the page, loaded jQuery, and can pull the data for the initally loaded color, but nothing seems to allow me to execute click events. </p> <p>here is what I'm trying:</p> <pre><code>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); } </code></pre> <p>This gives me:</p> <pre><code>console&gt; Price is: $19.95 console&gt; Selection is: blue console&gt; [Object Object] console&gt; TypeError: 'undefined' is not and object // repeating until I manually exit </code></pre> <p>no other code runs. I've also tried firing the event without jQuery like this:</p> <pre><code>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); </code></pre> <p>And running the function directly:</p> <pre><code>pPage.getColor(1); </code></pre> <p>And I get the same output. Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload