From: D&J G. <djg...@gm...> - 2008-02-27 21:55:46
|
Just off the top of my head: 1. If you call anchor.click(), you shouldn't have to trigger the JavaScript manually. 2. Try using the NicelyResynchronizingAjaxController. http://mguillem.wordpress.com/2007/07/24/htmlunit-re-synchronize-ajax-calls-for-simple-deterministic-test-automation/ Regards, Daniel On Wed, Feb 27, 2008 at 3:51 PM, Brian Munter <bm...@ya...> wrote: > We are trying to implement HTMLUnit at our client as > part of our testing strategy. Many of our apps rely > heavily on Ajax and JavaScript. I have a quick > question about an issue we are running into and > hopefully someone can provide an example solution :) > > We are trying to proof out a simple Ajax prototype > using HTML unit. Basically it just submits an Ajax > call and then uses "innerHTML" javascript to change a > div value on the page. We would like to inspect the > new value of this div. This is driven off a onclick > even on an anchor tag. The problem is after the click > event, when we inspect the div through HTMLUnit, it > still contains the original value and not the new one. > Below is our HTMLUnit code we are trying to use: > > final WebClient webClient = new WebClient(); > final HtmlPage page = (HtmlPage) > webClient.getPage("http://localhost:8080/test.jsp"); > HtmlAnchor anchor = (HtmlAnchor) > page.getAnchors().get(0); > System.out.println(anchor.getOnClickAttribute()); > page.executeJavaScript(anchor.getOnClickAttribute()); > HtmlPage page2 = (HtmlPage) anchor.click(); > HtmlElement he = page2.getHtmlElementById("testDiv"); > > The HTMLElement is the orininal value in this example. > The sample jsp is attached if you would like to see > exactly. > > > I appreciate any help. Thanks! > > > > > ____________________________________________________________________________________ > Looking for last minute shopping deals? > Find them fast with Yahoo! Search. > http://tools.search.yahoo.com/newsearch/category.php?category=shopping > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " > http://www.w3.org/TR/html4/loose.dtd"> > > <html> > <head> > <title>PVTest</title> > > <script type="text/javascript"> > function ajaxSubmit() > { > var xmlHttp; > > if (window.XMLHttpRequest) { // Non-IE browsers > xmlHttp = new XMLHttpRequest(); > } else if (window.ActiveXObject) { // IE > xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); > } > > xmlHttp.onreadystatechange=function() > { > if(xmlHttp.readyState==4) > { > document.getElementById('testDiv').innerHTML="NEW > DATA"; > } > } > > xmlHttp.open("GET","www.yahoo.com",true); > xmlHttp.send(); > } > </script> > > </head> > > <body> > <form> > <a href="#" onclick="ajaxSubmit();">My Link</a> > <div id="testDiv">Initial Data</div> > </form> > </body> > </html> > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > > -- Daniel Gredler http://daniel.gredler.net/ |