0

我正在尝试使用 htmlunit 访问以下表单中的按钮。由于该按钮没有名称,我想我必须使用 xPath 来解决它。我试图通过编写类字段来访问它

page.getByXPath("//input[@class='btn small  ']");

但不幸的是,这不起作用。

有人知道如何访问它吗?

<form id="login_form" class="login" action="/login" accept-charset="utf-8" method="post">
<input type="hidden" name="p" value="" id="page_url_p"/> <input type="hidden" name="dest"
 value="" id="page_url_p"/> <label>Email or
Username</label> <input id="user"
                        class="user" type="text" name="username" value=""/>
<script>$('user').focus();</script>

<label>Password</label> <input id="pass" class="pass" 
type="password" name="password"
                               value="" maxlength="256"/> <a class="forgot" href="http://www.mypage.com">Forgot your
password?</a>

<p id="" class="btn small  " style="" onmousedown="util.toggleClass(this, 
'active')" onmouseup="util.toggleClass(this, 'active')"
   onmouseover="util.toggleClass(this, 'hover')" 
onmouseout="util.toggleClass(this, 
'hover')"><a href="#" id="" class="" style="" onclick="$('login_form').submit();
return false;" target="" tabindex="">Sign in</a></p></form> 
4

1 回答 1

0
page.getByXPath("//p[@class='btn small']/a");

试试上面的。类在p标签上,按钮是a标签

另一种选择是page.getByXPath("//a[text()='Sign in']");

于 2013-09-06T04:35:13.593 回答