From: Amer Al-A. <ame...@ya...> - 2014-04-01 02:58:00
|
Here's a simple code <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Test</title> <script> function insertMyRow(){ var mytable = document.getElementById("MyTable"); var row = mytable.insertRow(1); var cell = row.insertCell(0); cell.innerHTML = "<h2>New SecondRow :) </h2>"; } </script> </head> <body> <table id="MyTable"> <tr><td><h3>First Row</h3></td></tr> <tr><td><h3>Second Row</h3></td></tr> </table> <a href="javascript:void(insertMyRow())" id="AddRowLink">Add new Second Row</a> </body> </html> final HtmlPage enclosedPage = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage(); final DomElement elementById = enclosedPage.getElementById("MyTable"); System.out.println("Before insert"); System.out.println(elementById.asXml()); final HtmlElement link = (HtmlElement) enclosedPage.getElementById("AddRowLink"); link.click(); System.out.println("\nAfter insert"); System.out.println(elementById.asXml()); Before insert <table id="MyTable"> <tbody> <tr> <td> <h3> First Row </h3> </td> </tr> <tr> <td> <h3> Second Row </h3> </td> </tr> </tbody> </table> After insert <table id="MyTable"> <tbody> <tr> <td> <h3> First Row </h3> </td> </tr> <tr> <td> <h3> Second Row </h3> </td> </tr> <tr> <td> <h2> New SecondRow :) </h2> </td> </tr> </tbody> </table> Sent from Yahoo Mail on Android |