javascript - querySelectorAll() print textcontent of all nodes -


this code using text content webpage. yet not working , not know doing wrong.

<tr style="color:#000000" class="odd">   <td style="padding:5px 5px 5px 10px" align="center"><input type="checkbox" name="cards[]" id="card_278002" value="278002"></td>   <td align="center">411756</td>   <td align="center">sherrie</td>   <td align="center">89852</td> </tr> 

and thats js code :

function get42() {     return document.queryselectorall('tr>td').textcontent; } console.log(page.evaluate(get42)); 

output : null .. doing wrong ?

you can't use document.queryselectorall that. returns nodelist. have take textcontent each node yourself.

longer way:

function get42() {     var tds = document.queryselectorall('td'),         result = [];     (var = 0; < tds.length; i++) {         result.push(tds[i].textcontent);     }     return result; } 

or shorter:

function get42() {     var tds = document.queryselectorall('td');     return array.prototype.map.call(tds, function(t) { return t.textcontent; }); } 

js fiddle


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -