Quantcast

Unable to get result / homepage after login ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unable to get result / homepage after login ?

subu
This post has NOT been accepted by the mailing list yet.
Hi,

Please help me get the result page after the login. I am always getting the same login page in return instead of the new page after login.
Below are my 2 classes but no luck;
Main Class:
---------------------------------
import java.util.logging.*;
public class WebsiteLogin {
        public static void main(String[] args) throws InterruptedException {
                Logger logger = Logger.getLogger("com.gargoylesoftware.htmlunit");
                logger.setLevel(Level.OFF);
                siteLogin client = new siteLogin("username", "*****");
                client.login();
        }
}
Another Class:
---------------------------------
import java.io.IOException;
import java.net.MalformedURLException;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;

public class siteLogin {
        private final WebClient WEB_CLIENT = new WebClient(BrowserVersion.CHROME);
        private final String username;
        private final String password;
        siteLogin(String username, String password){
                this.username = username;
                this.password = password;
                WEB_CLIENT.getCookieManager().setCookiesEnabled(true);
                WEB_CLIENT.getOptions().setJavaScriptEnabled(false);
                WEB_CLIENT.getOptions().setRedirectEnabled(true);
                WEB_CLIENT.getOptions().setThrowExceptionOnScriptError(false);
                WEB_CLIENT.getOptions().setCssEnabled(false);
                WEB_CLIENT.getOptions().setUseInsecureSSL(true);
                WEB_CLIENT.getOptions().setThrowExceptionOnFailingStatusCode(false);
                WEB_CLIENT.setAjaxController(new NicelyResynchronizingAjaxController());
               
        }
       
        public void login() throws InterruptedException{
                String loginURL = "https://www-304.ibm.com/usrsrvc/account/userservices/jsp/login.jsp";
                try {
                        HtmlPage loginPage = WEB_CLIENT.getPage(loginURL);
                        HtmlForm loginForm = loginPage.getFirstByXPath("//form[@id='ibmid-signin-form']");
                        loginForm.getInputByName("username").setValueAttribute(username);
                        loginForm.getInputByName("password").setValueAttribute(password);
                        HtmlButton button = (HtmlButton) loginForm.getElementsByTagName("button").get(0);
                        WebWindow window = loginPage.getEnclosingWindow();
                        button.click();
                        while(window.getEnclosedPage() == loginPage) {
                            Thread.sleep(500);
                            System.out.println(".............");
                        }
                        loginPage = (HtmlPage) window.getEnclosedPage();
                        System.out.println("2nd Page : "+loginPage.asText());
                       
                } catch (FailingHttpStatusCodeException e) {
                        e.printStackTrace();
                } catch (MalformedURLException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }
}

Thanks for all your time and help!!!!!
Loading...