javascript - How would you cycle through each image and check it for an error in a casperjs script? -


How will you cycle through each image on a given page and check to see if it is full Has it been or is it gone out?

P> and

  .error ()  

If the above works, can anybody show proper usage which will work in the casper script?

code I used looked like the following:

  var call_to_page = this.evaluate (function () {var fail_amount = 0; var pass_amount = 0; var pass_img_src = []; var fail_img_src = []; var img_src = []; $ ( "img") each (function () {$ (this) .load (function () {pass_amount ++ ;. pass_img_src.push ($ (this ) .attr ( "Src"));}). error (function () {fail_amount ++; fail_img_src.push ($ (this) .attr ( "src"));}); img_src.push ($ (this ) .attr ("src"));}); return [img_src, fail_amount, fail_img_src, pass_amount, pass_img_src];});  

Why does not anyone help why the code above works for me, it would be great that the page is coming properly and I am able to mess with DOM, not just . Load or Terror is thinking of images because of images being loaded, so Im still is looking for alternatives.

Casper JS function that can be used to check if a particular resource load occurs. Ressource is passed in a function, so custom constraints can be raised.

  casper.then (function () {var fail_amount = 0; var pass_amount = 0; var pass_img_src = []; var fail_img_src = []; var element = this.getElementsInfo ( "img" ); Elements.forEach (function (img) {if (img & amp; amp; img.attributes & amp; amp; amp; amp; amp; amp;; & amp; amp; amp; amp; amp;; casper.resourceExists {return resource.url.match {img.attributes.src ) & Amp; amp; amp; amp; resource.status> = 200 & amp; amp; resource.status & lt; 400;}) {pass_amount ++; pass_img_src.push (img.attributes.src);} else {fail_amount ++; fail_img_src.push (img.attributes.src);}}); this.echo (JSON.stringify ([fail_amount, fail_img_src, pass_amount, pass_img_src], undefined, 4));});  

This page can be loaded after loading. Therefore, there is no need to add some code in the context in a predefined form to the page.

In turn, the problem with your code can be that the callback never flows because the images have already expired. Therefore, there is no new information.

If you are not sure which errors are counted, then you can use the custom resources for all available types or errors to find out.

  Miscellaneous resources = []; // At least 'url' in a resource, 'status' casper.one ("Resource. Reside", function (resource) (if (resource.stage == "end") (if (resource.status & lt; 200 | | Resource.status> = 400) {resource.errorCode = resource.status; processing .errorString = resource.statusText;} resources.push (resource);}}); Casper.On ("resource.timeout" , Function (request) {request.status = -1; resources.push (request);}); Casper.one ("resource.error", function (resource error) {resourceError.status = -2; resources.push ( ResourceError);}); Function Resources Accents (URL) {Return Resource Filters (Function C) {return res.url.indexOf (url)! == -1;}). Length> 1;} Casper.start (url, function () {var elements = this.getElementsInfo ("img"); elements.forEach (function (img) {if (img & amp; & amp; img.attributes & amp; & amp; resourceExists (img. Attributes.src) & amp ;; Snsadniksists (img.attributes.src) .errorCode) {// pass} else {// fail}})}};  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -