Reputation: 31
I have a web page which has several tr
s and within each tr
there are several td
s. The structure looks like shown below
<tr bgcolor="#FFFFFF">
<td class="td1" style="text-align:left">TGHD03WYD15UGS</td>
<td class="td1" style="text-align:left">
<font style="font-weight:bold"> TicketType</font>
:The Grand Hotel, New Delhi,
<font style="font-weight:bold"> FirstName</font>
:Sanjali,
<font style="font-weight:bold"> LastName</font>
:Garg
</td>
I am able to get the list of tr
s using
this.getElementsInfo('selector');
When I iterate over the list I do get the tr
s but td
s show up only in html format. What I would like to have is td
objects which can be accessed using properties. The same would hold true in case of getting the inner objects from the last td
which holds font tag objects.
If I can navigate through the DOM as is possible in real javascript scenario, I would be able to get all the objects and will be able to access properties in them.
So far it doesn't looks possible in CasperJS. All I get in html property which gives me a string representation of that element, rather than giving me the object itself. I would like to navigate to the children of the element as in real javascript.
Is that possible?
Upvotes: 0
Views: 321
Reputation: 61892
You can navigate the DOM by using casper.evaluate
or variants. It executes the JavaScript given as a callback in the page context which is sandboxed. You cannot pass complex objects like DOM nodes. The docs say:
Note: The arguments and the return value to the evaluate function must be a simple primitive object. The rule of thumb: if it can be serialized via JSON, then it is fine.
Closures, functions, DOM nodes, etc. will not work!
Further reading:
Understanding the evaluate function in CasperJS
Why doesn't this.evaluate return DOM nodes correctly?
Iterating over a grid with CasperJS
Upvotes: 1