From: David D.K. <ddk...@ki...> - 2005-02-05 17:10:38
|
I strongly recommend adding unique "id" attributes to the HTML output by the JavaScript, then finding the HTML DOM objects using the IDs with the APIs provided by Htmlunit. This is much easier (and less error-prone) than relying on the structure of the document to find the tags you're looking for. And if you need to verify text on a page, use SPAN tags with a unique "id" attribute, too. Dave On Feb 4, 2005, at 2:44 AM, Marc Guillemot wrote: > Hi Jun, > > htmlunit can handle html code dynamically generated with > document.write... to a certain extent (for example, document.write in > the head currently make problems). > In your example, if it works correctly, you should find the <script> > elements in the td, as well as the generated content. > What errors do you become? How do you test that the table cell only > contains the <script....>? > > Marc. > > Jun Ma wrote: >> Hi, there >> I am a new comer for HtmlUnit. The Web application I am testing >> employs quite a lot Javascript code. It uses a Javascript code to >> generate a tool bar. The HTML code looks like the attached one. >> The page has a table. This table has two rows. In the first row, >> there are two HTML links. In the second row, there is tool bar. The >> toolbar.Write() method dynamically generates a piece of HTML code, >> like: <img src=..... onClick="......"... />. This code represents a >> button on this tool bar. >> My question is that how I use HTMLUnit to access this javascript >> generated HTML object. >> Via HTMLUnit, I can get the objects for the HTML Anchors defined >> in the first row of this table. However, I can not get the Javascript >> generated HTML objects. When I got the object of that Table cell, it >> only contains "<script language="javascript"> >> toolbarContainer.begin(); toolbar.write(); toolbarContainer.end(); >> </script>", not the <img ....> objects I am expecting. >> Do you know how to use HTMLUnit to manipulate the HTML objects >> dynamically generated by Javascript? >> Thanks a lot. >> Jun >> [HTML removed] > |