File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes cannot get https page details Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "cannot get https page details" Watch "cannot get https page details" New topic
Author

cannot get https page details

Prasath Premkumar
Ranch Hand

Joined: Nov 13, 2008
Posts: 43
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

Moving to our testing forum since it is about a testing tool.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot get https page details