Hi All,
Am new to using HTMLUnit.I wrote a sample code(to emulate opening of website google.com and enter a value say "html" in the text field and click the Search button) .The code is as follows
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebWindow;
import java.util.*;
import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.*;
import java.io.*;
import java.net.*;
import junit.framework.TestCase;
public class newhtmlunit extends TestCase {
public void testHomePage()
{
try
{
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
webClient.setThrowExceptionOnScriptError(false);
webClient.setThrowExceptionOnFailingStatusCode(fal se);
webClient.setRedirectEnabled(true);
webClient.setJavaScriptEnabled(true);
URL strurl = new URL("http://www.google.com");
System.out.println("Test msg"+strurl);
HtmlPage loginpage = (HtmlPage)webClient.getPage(strurl);
HtmlForm form = loginpage.getFormByName("f");
HtmlTextInput searchvalue=(HtmlTextInput)form.getInputByName("q" );
searchvalue.setValueAttribute("html");
System.out.println("The value is"+searchvalue.getValueAttribute());
form.submit("btnG");
}
catch(Exception e)
{
System.out.println("Exception msg is "+e);
}
}
}
However am getting the following error
com.gargoylesoftware.htmlunit.javascript.StrictErr orReporter error
[SEVERE: error: message=[syntax error] sourceName=[Window.eval()] line=[1] lineSource=[( )] lineOffset=[4]..........
[cat=System,part=256.6]: ======= EXCEPTION START ========
[Exception class=[org.mozilla.javascript.EvaluatorException]
com.gargoylesoftware.htmlunit.ScriptException: syntax error (Window.eval()#1)
The exception was very huge.Please let me know if you need to look into the whole exception.
Please let me know what am doing wrong here.