<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>
我想在表单中提交按钮。提交没有名称或ID
final HtmlForm form = resultPage.getFirstByXPath("//form[@action='security_check']");
final HtmlTextInput textField = form.getInputByName("username");
final HtmlPasswordInput pwd = form.getInputByName("password");
textField.setValueAttribute("username");
pwd.setValueAttribute("password-2016");
如何获取按钮并提交表单。
答案 0 :(得分:0)
为什么不根据数据获取?qa?
button = form.getFirstByXPath("//button[@data-qa='login.submit']");
button.click();