Question

I have webform which I am filling with credentials. Then I want to click on login link. But it still gives me the same page in which I am clicking.

HtmlForm loginForm = loginPage.getFormByName("Login1Form");
HtmlTextInput inLoginName = loginForm.getInputByName("loginId");
HtmlPasswordInput inPassword = loginForm.getInputByName("passwd");
HtmlTextInput inCaptcha = loginForm.getInputByName("checkcode");

inLoginName.setText(loginName);
inPassword.setText(password);
inCaptcha.setText(captcha.toUpperCase());

//HtmlElement loginLink =loginPage.getFirstByXPath("//a[@href=\"javascript:submitPB('9');\"]");
HtmlAnchor loginLink = loginPage.getAnchorByHref("javascript:submitPB('9');");
HtmlPage resultPage = resultPage = loginLink.click();

And resultPage even has same object id as loginPage has. I've tried webClient.wait methods and all I've found here. But nothing is working for me.

Here is html link I need to click on

<a href="javascript:submitPB('9');">
    <img src="images/pf/login-001.gif" width="43" height="21" border="0" alt="">
</a>

Any ideas please? Thanks

EDIT:// WebClient settings:

mWebClient = new WebClient(BrowserVersion.FIREFOX_3_6);
mWebClient.getOptions().setJavaScriptEnabled(true);
mWebClient.getOptions().setRedirectEnabled(true);
mWebClient.setAjaxController(new NicelyResynchronizingAjaxController());
mWebClient.getCookieManager().setCookiesEnabled(true);
Was it helpful?

Solution

Seems that sending WebRequest directly works. So first I load login page for captcha etc to be loaded, and then:

String formData = String.format(LOGIN=LOGIN&PB=9&isAA=&sso=&initP=gogo&loginId=%s&passwd=%s&checkcode=%s", loginName, password, captcha.toUpperCase());
WebRequest req = new WebRequest(new URL(url), HttpMethod.POST);
req.setRequestBody(formData);
resultPage = (HtmlPage) getWebClient().getPage(req);

And new page is returned. However then that page says that I dont support frames but that is all different issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top