Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot get https page details

 
Prasath Premkumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to extract data from a wesite. After i give the login details the new page opens through javascript window. So, when i provide the login details to the program it should process javasript , get the url & go to the new page. then i can get a table from the new page & extract data. This is the senario. How can i do that using HtmlUnit?

I wrote a sample application; i have posted the code below;

public class Main{

public static void main(String args[]){
try {
Main main = new Main();
main.submittingForm();
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

}
public void submittingForm() throws Exception {
final WebClient webClient = new WebClient();
webClient.setJavaScriptEnabled(true);
ProxyConfig proxy = new ProxyConfig();
proxy.setProxyHost("*****");
proxy.setProxyPort(****);
webClient.setProxyConfig(proxy);
// Get the first page
final HtmlPage page1 = webClient.getPage("some url");

// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("form1");

final HtmlSubmitInput button = form.getInputByName("Submit");
final HtmlTextInput textField1 = form.getInputByName("user_id");
final HtmlPasswordInput textField2 = form.getInputByName("password1");

// Change the value of the text field
textField1.setValueAttribute("my username");
textField2.setValueAttribute("my password");

// Now submit the form by clicking the button and get back the second page.
final Page page2 = button.click();
final HtmlPage toTest = (HtmlPage)page2;
final List<?> divs = toTest.getByXPath("//table");
for(int i = 0; i<divs.size();i++){
final HtmlTable table = (HtmlTable)divs.get(i);
for (final HtmlTableRow row : table.getRows()) {
// System.out.println("Found row");
for (final HtmlTableCell cell : row.getCells()) {
System.out.println(" Found cell: " + cell.asText());
}
}
}
}

}


bt the program gives the following chained exception:

======= EXCEPTION START ========
Exception class=[org.mozilla.javascript.WrappedException]
com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Inappropriate array length. (https://corporate.ndbbank.com/ibankretail/menuCookie.js#48) (script in https://corporate.ndbbank.com/ibankretail/Home.jsp from (4, 38) to (32, 14)#27)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:513)
at org.mozilla.javascript.Context.call(Context.java:515)
at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:507)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:444)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:961)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:152)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:165)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:586)
at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:916)
at org.mozilla.javascript.Context.call(Context.java:515)
at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:507)
at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:921)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1206)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:173)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:445)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:327)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:352)
at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:171)
at com.gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction(HtmlSubmitInput.java:78)
at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:148)
at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:107)
at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:76)
at siteextractor.Main.submittingForm(Main.java:62)
at siteextractor.SampathBank.main(SampathBank.java:47)
Caused by: org.mozilla.javascript.WrappedException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Inappropriate array length. (https://corporate.ndbbank.com/ibankretail/menuCookie.js#48) (script in https://corporate.ndbbank.com/ibankretail/Home.jsp from (4, 38) to (32, 14)#27)
at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1773)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:183)
at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:476)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3330)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:192)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:82)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:472)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$6.doRun(JavaScriptEngine.java:437)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:507)
... 23 more
and so on................


I'm really stuck with it. What can be the problem?

Please help me. Thanks in advance. >
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our testing forum since it is about a testing tool.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic