Hi all :) I'm new in HtmlUnit (Java). It's my first time to use HtmlUnit stuffs. I'm having some issues to log-in to a web page.
And some part of the source of the web site is below.
<table>
<tr>
<td colspan="2">
<div class="AlignRight">
<div class="Button" id="loginButton">
<div class="Left"> </div>
<div class="Middle"><a href="javascript:submitForm(document.getElementById('localLogin'), 'submit');"><strong>log-in</strong></a></div>
<div class="Right"> </div>
</div>
</div>
</td>
</tr>
</table>
And the some part of the code that i worte is below and plus i set "webClient.setJavaScriptEnabled(true);" already.
HtmlPage page = (HtmlPage) webClient.getPage("https://************");
HtmlForm form = page.getFormByName("login");
HtmlElement button = form.getElementById("loginButton");
// Enter login and passwd
form.getInputByName("username").setValueAttribute("******");
form.getInputByName("password").setValueAttribute("******");
page = (HtmlPage) button.click();
System.out.println(page.getUrl());
System.out.println("Success");
so.. after running the code, The url should be changed as after clicking the button, but I couldn't see any difference. There's no error for running but just i can't see the changed Url..
Is there anything wrong ? .. Please give me some advice T_T ! Thanks in advance :D
您可以尝试手动执行javascript:
page.executeJavaScript("javascript:submitForm(document.getElementById('localLogin'), 'submit');");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.