Ruby 机械化 - 区分两种形式及其内容
Ruby mechanize - discriminate two forms with their content
我有两个具有相同操作的表单,并提交按钮文本。只有里面的文字发生变化
<li>
<form name="login" method="post" action="">
<input name="returnURL" value="/cap/dashboard/home" type="hidden">
<input name="destURL" value="" type="hidden">
<button name="login" type="submit" class="btn-primary">
<span aria-hidden="true">Continuer</span>
</button>
<h2>textA</h2>
</form>
</li>
<li>
<form name="login" method="post" action="">
<input name="returnURL" value="/cap/dashboard/home" type="hidden">
<input name="destURL" value="" type="hidden">
<button name="login" type="submit" class="btn-primary">
<span aria-hidden="true">Continuer</span>
</button>
<h2>textB</h2>
</form>
</li>
如何提交正确的表格?
您可以使用form_node
搜索css/xpath:
page.forms.find{|f| f.form_node.at('h2:contains("textB")')}
不过没关系,在您的示例中,两种形式都做同样的事情。
我有两个具有相同操作的表单,并提交按钮文本。只有里面的文字发生变化
<li>
<form name="login" method="post" action="">
<input name="returnURL" value="/cap/dashboard/home" type="hidden">
<input name="destURL" value="" type="hidden">
<button name="login" type="submit" class="btn-primary">
<span aria-hidden="true">Continuer</span>
</button>
<h2>textA</h2>
</form>
</li>
<li>
<form name="login" method="post" action="">
<input name="returnURL" value="/cap/dashboard/home" type="hidden">
<input name="destURL" value="" type="hidden">
<button name="login" type="submit" class="btn-primary">
<span aria-hidden="true">Continuer</span>
</button>
<h2>textB</h2>
</form>
</li>
如何提交正确的表格?
您可以使用form_node
搜索css/xpath:
page.forms.find{|f| f.form_node.at('h2:contains("textB")')}
不过没关系,在您的示例中,两种形式都做同样的事情。