Hi,
I try to get an HtmlPage by following a link that has an onClick
attribute but I get an Exception. If I follow the link with a browser I
have no problem.
The link is inside a form named "f_search" and "type_field" is the name
of a hidden field inside the form (see HtmlAnchor in the trace).
I try to run the following code:
public static void main(String[] args) throws
FailingHttpStatusCodeException, IOException
{
WebClient client = new WebClient(BrowserVersion.FULL_FEATURED_BROWSER);
client.setRedirectEnabled(true);
System.out.println("javascript enabled: " +
client.isJavaScriptEnabled());
URL url = new URL("http://myhost/index.html");
HtmlPage enterPoint = (HtmlPage) client.getPage(url);
HtmlAnchor submit = (HtmlAnchor) enterPoint.getAnchors().get(44);
System.out.println(submit);
HtmlPage result = (HtmlPage) submit.click();
}
But here is what I get in the console:
javascript enabled: true
Oct 21, 2003 2:26:53 PM org.apache.commons.httpclient.HttpMethodBase
processRedirectResponse
INFO: Redirect requested but followRedirects is disabled
Oct 21, 2003 2:26:53 PM org.apache.commons.httpclient.HttpMethodBase
processRedirectResponse
INFO: Redirect requested but followRedirects is disabled
HtmlAnchor[<a href="javascript:document.f_search.submit();"
onclick="document.f_search.type_field.value='RESULTS';
return(val_form());">]
Exception in thread "main" ======= EXCEPTION START ========
EcmaError: lineNumber=[14] column=[0] lineSource=[null]
name=[ConversionError] sourceName=[Embedded script] message=[The
undefined value has no properties.] errorObject=[ConversionError: The
undefined value has no properties.]
com.gargoylesoftware.htmlunit.ScriptException: The undefined value has
no properties.
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:250)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:886)
at
com.gargoylesoftware.htmlunit.html.HtmlAnchor.click(HtmlAnchor.java:85)
at org.xenata.criq.Criq.main(Criq.java:37)
Enclosed exception:
ConversionError: The undefined value has no properties. (Embedded
script; line 14)
at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597)
at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557)
at org.mozilla.javascript.ScriptRuntime.getProp(ScriptRuntime.java:712)
at org.mozilla.javascript.gen.c4.call(Embedded script:14)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1191)
at org.mozilla.javascript.gen.c27.call(Wrapper definition for onClick
handler:1)
at
org.mozilla.javascript.optimizer.OptRuntime.callSimple(OptRuntime.java:275)
at org.mozilla.javascript.gen.c29.call(onClick handler:1)
at org.mozilla.javascript.gen.c29.exec(onClick handler)
at org.mozilla.javascript.Context.evaluateReader(Context.java:820)
at org.mozilla.javascript.Context.evaluateString(Context.java:784)
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:242)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:886)
at
com.gargoylesoftware.htmlunit.html.HtmlAnchor.click(HtmlAnchor.java:85)
at org.xenata.criq.Criq.main(Criq.java:37)
== CALLING JAVASCRIPT ==
GargoyleWrapper0()
======= EXCEPTION END ========
What's the problem?
Oscar
|