Java HtmlUnit无法在页面上查找元素

时间:2015-07-15 23:31:11

标签: java htmlunit

我之前已使用https://jsfiddle.net/通过表单发送登录信息,并且我一直试图再次尝试,但却无法让它在此网站上运行:{ {3}}

使用代码

final HtmlPage page1 = webClient.getPage("http://www.runescape.com/companion/comapp.ws"); 
final HtmlForm form = (HtmlForm) page1.getForms().get(0);`

什么都不返回,即使你检查页面上的元素:

<form name="loginForm" ng-submit="login()" autocomplete="off" class="ng-pristine ng-invalid ng-invalid-required"> ... </form> 显然存在。

还有代码

final HtmlPage page1 = webClient.getPage("http://www.runescape.com/companion/comapp.ws");
final HtmlTextInput textField = page1.getFirstByXPath("//input[@id='username']");

final HtmlPage page1 = webClient.getPage("http://www.runescape.com/companion/comapp.ws");
final HtmlTextInput textField = page1.getElementByName("username");
尽管有一个名为&#34; username&#34;的输入字段,但

都没有返回任何内容。 ID为&#34;用户名&#34;

编辑:

<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>

我不确定我是否会出现这种错误,或者这种方法由于某些我没有看到的原因而无法在这个特定的页面上工作。我对代码或任何其他登录方法的修复都非常感激。谢谢!

1 个答案:

答案 0 :(得分:0)

您始终可以构建httpwebrequest并以此方式登录。

相关问题