Hello to all,
May be someone could help me with this:
I want to get the number of rows of the nested table from a simple HTML table in code shown below.
When I run it locally in my machine save it the code as file.html or in this link Edit fiddle - JSFiddle - Code Playground and I run the following Javascript code on Chrome console, I get correctly the number of rows (3 in this case).
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
getElementByXpath("//*[@id='main']/table[2]/tbody").rows.length;
Now I go to Kantu and running the same javascript code like this:
executeScript_Sandbox | function getElementByXpath(path) { ...} var r=getElementByXpath("//*[@id='main']/table[2]/tbody").rows.length; return r; | x
echo | ${x} |
I get this error:
[error] Error in executeScript_Sandbox code: Cannot read property 'rows' of null
What is missing in my code?
The HTML code is:
<table border = 1 bgcolor="#FFE83A">
<tbody>
<tr>
<td id = "main">
<table id = "table_x">...</table>
<div>...</div>
<iframe src="javascript:false;" id="iframe_x" name="iframe_x" style="display:none" height="0" width="0" filterlink="?"></iframe>
<table class="table2_class" summary="MySummary" border = 1 bgcolor="#38FF66">
<thead>...</thead>
<tbody>
<tr class="a1" >
<td class="td_class">1</td>
<td class="td_class">N</td>
<td class="td_class_1">
<div dir="" class="zzz">
<div class="div_class">
<a href="...">Some text</a>
</div>
</div>
</td>
</tr>
<tr class="b1" >
<td class="td_class">4</td>
<td class="td_class">W</td>
<td class="td_class_1">
<div dir="" class="zzz">
<div class="div_class">
<a href="...">Some text</a>
</div>
</div>
</td>
</tr>
<tr class="a1" >
<td class="td_class">7</td>
<td class="td_class">R</td>
<td class="td_class_1">
<div dir="" class="zzz">
<div class="div_class">
<a href="...">Some text</a>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
Thanks in advance.