如何使用Htmlunit

时间:2016-10-15 05:41:47

标签: java htmlunit

如何登录具有以下表单数据的网站,提交没有名称或ID

String URL="http://127.0.0.0/zero/login.jsp";
final HtmlPage resultPage = webclient.getPage(URL);

<form name="login" action="security_check" method='POST'>
                <input data-qa="login.username" type="text" class="text-box text-box--fluid" placeholder="Username" autofocus=true name='username'/>
                <input data-qa="login.password" type="password" class="text-box text-box--fluid" placeholder="Password" name='password'/>
                <button data-qa="login.submit" type="submit" class="btn btn--primary btn--large" onclick="submit_onclick(this)">Log In</button>
</form>

我尝试过DefaultCredentialsProvider,但它无效

1 个答案:

答案 0 :(得分:0)

您可以尝试按xpath

访问提交按钮
HtmlButton button = page.getElementByXpath("//form[@name='login']/button").get(0);
page = (HtmlPage) button.click();