I've used HtmlUnit to send a login through a form before and I've been trying to do it again but just can't get it to work on this site: http://www.runescape.com/companion/comapp.ws
Using the code
final HtmlPage page1 = webClient.getPage("http://www.runescape.com/companion/comapp.ws");
final HtmlForm form = (HtmlForm) page1.getForms().get(0);`
Returns nothing, even though when you inspect element on the page the form:
<form name="loginForm" ng-submit="login()" autocomplete="off" class="ng-pristine ng-invalid ng-invalid-required"> ... </form>
clearly exists.
Also the code
final HtmlPage page1 = webClient.getPage("http://www.runescape.com/companion/comapp.ws");
final HtmlTextInput textField = page1.getFirstByXPath("//input[@id='username']");
and
final HtmlPage page1 = webClient.getPage("http://www.runescape.com/companion/comapp.ws");
final HtmlTextInput textField = page1.getElementByName("username");
both return nothing despite there being an input field named "username" with the id of "username"
Edit:
<form name="loginForm" ng-submit="login()" autocomplete="off" class="ng-pristine ng-invalid ng-invalid-required">
<button type="submit" class="icon-login" ng-disabled="!loginForm.$valid" disabled="disabled"></button>
<input type="text" name="username" id="username" placeholder="Username / Email" autocapitalize="off" autocorrect="off" required="" ng-model="credentials.username" class="ng-pristine ng-invalid ng-invalid-required" data-emoji_font="true" style="font-family: MuseoSans500, sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol', Symbola, EmojiSymbols !important;">
<input type="password" name="password" id="password" placeholder="Password" autocapitalize="off" autocorrect="off" required="" ng-model="credentials.password" class="ng-pristine ng-invalid ng-invalid-required">
</form>
I'm not sure if I'm going about this wrong, or this method just wont work on this particular page for some reason that I'm not seeing. A fix to my code, or any alternative methods of logging in are much appreciated. Thanks!