From: Dave K. <dko...@ve...> - 2005-04-26 17:44:42
|
Thanks for the response. I was really more interested in whether the javascript was legit or not. I have worked around the problem by recoding the javascript - not ideal, but it will work for me. I do seem to have a broader problem I would like to ask about. It appears that using webClient.getPage(url); on the page in question (with recoded javascript) does not fully execute the javascript. Again, this is not my code, but the gist of the functionality is: - original javascript embedded in page pulls down a larger javascript file from the server using document.write() - this additional javascript sets functions for window.onload() and window.onunload() (as seen in my previous question) - these functions call a bunch of other functions, the ultimate result of which is to fire off a message to another server to report some performance stats I'm snooping the NIC on the server that receives the performance data and I am not seeing any indication of a connection from the server running htmlunit. I understand that the onunload() would not be run as there is currently no event handler for it, but I thought the onload() would be run. Let me ask, fundamentally, is the code below enough to be accomplishing what I expect? Or do I need to do more to actually execute the onload function? Thanks, Dave At 04:06 AM 4/26/2005, Marc Guillemot wrote: >Hi Dave, > >the problem seems to come from the syntax "function window::onLoad()". >Trying following code: > > >in Mozilla, Firefox and IE, it only works with IE and I get the same >errors in Mozilla and Firefox as the one reported >by htmlunit. Therefore I guess that your server generates other javascript >for an non IE browser. What happens if you >simulate Mozilla with htmlunit to visit your page? > >I have to say that it is the first time that I see this syntax but >htmlunit should support it when simulating IE as it >is supported by IE. Not sure of Rhino (the underlying javascript engine) >can do it. Please open a bug issue for it. > >If you want to simulate IE and can't change the js delivered by the >server, you can write a ScriptPreProcessor to adapt >the js before it is executed by htmlunit changing for instance >function window::onLoad() { IE_OnLoad(); } >to >window.onload = function() { IE_OnLoad(); } > >Marc. > > > import junit.framework.TestCase; > > import com.gargoylesoftware.htmlunit.*; > > import com.gargoylesoftware.htmlunit.html.*; > > import java.net.*; > > > > public class test1 extends TestCase { > > > > public static void main(String[] args) { > > > > System.setProperty("com.gargoylesoft.htmlunit.javascript", "debug"); > > System.out.println("Start test:"); > > System.out.println("Using URL="+args[0]); > > for (int i=0; i<=100000; i++){ > > System.out.print("Run: "); > > System.out.println(i); > > try { > > testSearch(args[0]); > > } catch (Exception e){ > > System.out.println("Got an exception"); > > System.out.println(e.getMessage()); > > } > > } > > } > > > > public static void testSearch(String urltouse) throws Exception { > > final WebClient webClient = new > > WebClient(BrowserVersion.INTERNET_EXPLORER_6_0); > > final URL url = new URL(urltouse); > > final HtmlPage page = (HtmlPage)webClient.getPage(url); > > } > > > > > > } |