简体   繁体   English

如何使用HTMLUnit中的表单数据登录网站

[英]How to login into the site using form data in Htmlunit

How to login to site which has the below form data, the submit does't have name or id 如何登录具有以下表单数据的站点,提交的人没有名称或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>

I have tried DefaultCredentialsProvider but it's not working 我已经尝试过DefaultCredentialsProvider,但无法正常工作

You can try to access the submit button by its xpath : 您可以尝试通过xpath访问xpath按钮:

HtmlButton button = page.getElementByXpath("//form[@name='login']/button").get(0);
page = (HtmlPage) button.click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM