我有一个页面,其中有许多编辑按钮。每个按钮都有相同的id,即enable_edit_content。如何点击特定按钮。
这是我必须点击
的代码<div class="sub-controls" id="motion_eligibility_entry-subcontrols">
<button class="btnedit" **id="enable_edit_content"** name="button" type="button"></button>
<input class="btnsave submit_form" id="save_motions_eligibility_entry" name="commit"
type="submit" value="" disabled="disabled">
<button class="btnkill" id="cancel_content" name="button" type="button"
disabled="disabled"></button>
</div>
任何帮助都将受到高度赞赏。 我试过但无法得到我的结果: -
1) page.all(:css, '#enable_edit_content').each_with_index do |el, i|
i += 1
if i == 3
el.click
end
end
2)find(:xpath, "//div[@id='motion_eligibility_entry-subcontrols']/button[1]").click
答案 0 :(得分:0)
您还可以使用内部块来缩小css选择器的范围。
within('.sub-controls) do
page.find('#enable_edit_content).click
end
由于这个问题,我强烈建议避免使用xpath并使用css选择器!
希望这有帮助。