You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by suheal hanjgikar <su...@hotmail.com> on 2003/06/06 18:16:00 UTC
Redirect requested but followRedirects is disabled
Hi,
I am trying to write a sample test program using HtmlUnit.
(http://htmlunit.sourceforge.net/)
However it fails with an execption. Can you please help me out
in resolving the issue.
Thanks,
Suheal
The program code:
Note : Please put the appropriate proxy server name
/***********************************************************************************************/
import java.net.URL;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
public class testhtml
{
public static void main (String args[])
{
try
{
final WebClient webClient = new
WebClient(BrowserVersion.INTERNET_EXPLORER_6_0, "MyProxy", 80);
webClient.setRedirectEnabled (true);
System.out.println ("webclient created");
final URL url = new URL("http://www.mail.yahoo.com");
System.out.println ("url created");
final HtmlPage page = (HtmlPage)webClient.getPage(url);
System.out.println ("got the html page");
System.out.println ("title : " + page.getTitleText ());
HtmlTextInput username = (HtmlTextInput)page.getHtmlElementById
("login");
if (username == null)
{
System.out.println ("login not found");
return;
}
HtmlPasswordInput passwd = (HtmlPasswordInput)page.getHtmlElementById
("passwd");
if (passwd == null)
{
System.out.println ("passwd not found");
return;
}
HtmlSubmitInput submitbt = (HtmlSubmitInput) page.getHtmlElementById
(".save");
if (submitbt == null)
{
System.out.println ("submitbt not found");
return;
}
System.out.println ("eof program....");
}
catch (Exception excp)
{
excp.printStackTrace ();
}
}// eof main
}// eof myhtmltest
/***********************************************************************************************/
The excpetion that it throws.
/***********************************************************************************************/
[INFO] HttpMethod - -Redirect requested but followRedirects is disabled
com.gargoylesoftware.htmlunit.ScriptException: The undefined value has no
proper
ties.
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(Jav
aScriptEngine.java:199)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossib
le(HtmlPage.java:770)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.executeBodyOnLoadHandlerI
fNeeded(HtmlPage.java:900)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:
134)
at
com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:322)
at
com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:242)
at
com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:186)
at testhtml.main(testhtml.java:23)
/***********************************************************************************************/
_________________________________________________________________
Horror films in Bollywood. Are they worth it?
http://server1.msn.co.in/features/horror/index.asp Get all the dope!