1

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);
bakua
  • 13,704
  • 7
  • 43
  • 62
  • have you enabled javascript in the HTMLUnit? Also ensure your loginLink is the correct link – Shervin Asgari Feb 07 '14 at 13:09
  • I've edited my webClient to question. When I look into login link variable it looks ok. Also there is only one link with submitPB('9') on page. – bakua Feb 07 '14 at 13:24
  • Your question can be summarised in *I click a button and nothing happens.* Hard to help you with that. Provide more information, please. You said you've tried the *wait* methods. I would like to see that. Is the same I've proposed in many [similar questions](http://stackoverflow.com/questions/17843521)? How have you implemented it? – Mosty Mostacho Feb 07 '14 at 15:13
  • I download image from HtmlPage and let user to write it – bakua Feb 09 '14 at 16:55

1 Answers1

1

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.

bakua
  • 13,704
  • 7
  • 43
  • 62