试图填写水豚的第二个文本框 [英] Trying to fillin second text box in capybara

查看:65
本文介绍了试图填写水豚的第二个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试填写两个标记为id = admin_passsword的文本框。我可以轻松访问第一个文本框,但是由于占位符和上方的标签没有其他区别,因此我不知道如何访问第二个文本框以填写该字段。

I am trying to fill in both textboxes that are labeled id="admin_passsword". I can access the first on easy but since there are NO differences other than the placeholder and the label above it I do not know how to access the second textbox to fill in that field.

<div class="fields">
    <div class="field-row">
      <label for="admin_email">Email</label>
      <input autocapitalize="off" id="admin_email" name="admin[email]" placeholder="Email" size="30" type="text" value="">
    </div>
    <div class="field-row">
      <label for="admin_serial_number">Serial number</label>
      <input id="admin_serial_number" name="admin[serial_number]" placeholder="Serial Number" size="30" type="text">
    </div>
    <div class="field-row">
      <label for="admin_password">Password</label>
      <input id="admin_password" name="admin[password]" placeholder="Password" size="30" type="password">
    </div>
    <div class="field-row">
      <label for="admin_password_confirmation">Password confirmation</label>
      <input id="admin_password" name="admin[password]" placeholder="Confirm Password" size="30" type="password">
    </div>
  </div>


推荐答案

在Capybara 2.1中,该方法有效:

With Capybara 2.1, this works:

  fill_in("Password", with: '123456', :match => :prefer_exact)
  fill_in("Password confirmation", with: '123456', :match => :prefer_exact)

请从上述评论中准确选择链接::prefer_exact是在Capybara 1.x中存在的行为。如果找到多个匹配项,其中一些是完全匹配的,而有些则没有,则返回第一个eaxctly匹配元素。

Prefer exact from the above comment's link: :prefer_exact is the behaviour present in Capybara 1.x. If multiple matches are found, some of which are exact, and some of which are not, then the first eaxctly matching element is returned.

这篇关于试图填写水豚的第二个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆