javascript - Printing elements from XPath results in more than the elements -


What I want to do is determined by a xpath that was set to me but getElementsByXPath There is a problem using the function in CasperJS.

  var casper = require ('casper'). Make ({verbose: false, log-level: 'debug'}); Casper.UserGent ("Mozilla / 5.0 (Windows NT 6.1; WOW64) Apple WebKat / 537.36 (KFTM, like Geico) Chrome / 28.0.1500.72 Safari / 537.36"); Casper.start (); Casper.thenOpen ('http://www.uky.edu', function () {content = casper.evaluate (function () {returns __utils __. GetElementsByXPath ('// div [@id = \' container \ '] / Section [@id = \ 'content \'] / [@ class = \ 'social tab clearfile \'] / div [@id = \ 'usual2 \'] / div [@id = \ 'tab11 \'] / Shape [@ class = \ 'youtube \'] / h4 / a ');});}); Casper.run (function () {this.echo (JSON.stringify (content)); this.echo ('completed') exit ();});   

The data does not stop recalling and it is certainly not returning to the particular string that I see, it seems that it is returning the data for the entire webpage

I'm trying this with a practically empty webpage with just one div and received the same issue, I used // div for xpath and received the following >

  ["align": "", "property": {"length": 0}, "baseURI": "http: // Download2012.ad.uky.edu/caspertest.php "," childElementCount ": 0," childNodes ":" "" "," length ": 1}," hair color ": {" length ": 0}," classlist "," Classname ":" "," client high ":", "Dir": "", "draggable": false, "", "cli entLeft": 0, "clientTop" : "", "ClientWidth": 384, "contentEditable": "heir", "dataset": {}, "dir" "first child": blank, "first elementbill": "", "hidden": false, "id False, "Lang": "", "Final" group: {"Attributes": "Test", "Interactive HTML": "Test", "Interstitial text": "Test 2", " "," Basuri ":" http: //download2012.ad.uky.ed u / caspertest.php "," childNodes ": { "" "": "" "" "", "First Child": "", "Last Child": "", "Length": 5, "Local Name": "", "Nominate": "# 2", "Node Type": 3, "NodeVela": "Test 2", "Owner Document": blank, "Parental Element" : "Test Name", "Waste Text": "Test 2"}, "Parent Node": "", "Div", "Old Sibling": "", "Text Content": "Test 2", " "Element": "" "NamespaceURI": "http: //www.w3.org/1999/xhtml", "nextElementSibling": "" target.sibling ": null, nn" name ":" div "," not Type ": 1," Offset Heights ": 20," offset left ": 8," OffsetPrint ": {" align ":" "," attributes ": {" length ": 0}," background " : "", "Besurai": "http: //download.e. 2012. ad.uku.edu/caspertest.php", "bgColor": "" childElementCount "/" childNodes ": {" 0 ": blank," 1 " {"0": zero, "length": 1}, "class list": {"length": 0}, "square name": tap, "", "length": 3}, "children": {"0": "" "," ClientHeight ": 300," clientLeft ": 0," clienttop ": 0," clientwidth ": 400," contentEditable ":" heir "," dataset ": {}," dir ":" "," Draggable ":" "" basic ":" "," basuri ":" http://download2012.ad.uky.edu/ caspertest.php "," childNodes ": {" length ": 0}," Data ":" "Nickname": "", "next silk": "", "first chill": "", "length": 5, "local name": "", "namespace": "", "next sibling": empty, "Nodenamed e":   

and so on.

You can not return DOM elements to page code in CasperJS __ utils __. GetElementsByXPath instead of document.querySelectorAll is used (with the adjusted CSS selector), the result will be an array of undefined values ​​it __ utils There is no case for __. GetElementsByXPath . Snapshots of DOM elements are returned which are actually partial serials. The problem is that they are in the circular context of the document and will continue to grow.

From:

Note: The value for the argument and return evaluation value should be a simple primitive object. Rule of Thumb: If it can be serialized via JSON, then it is OK.

Closer, functions, dom nodes etc. will not work!

You need to do everything you need to do in the page context, for example element as a string:

  Content = casper.evaluate (function () {return __utils __. GetElementByX path (some selectors). OuterHTML;});    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -