LoginSignup
14

More than 5 years have passed since last update.

Capybaraでfill_inを使わずにテキストボックスに入力する

Posted at

概要

idもlabelもないテキストボックスはfill_inメソッドが使えないようなのですが、
入力したかったので試してみました。
capybaraのfill_inメソッドが、inputタグに対してset("入力")しているだけだったので、
fill_inを使わずにテキストボックスに入力しました。

実装

class="hoge" 下の最初の type=text の最初のinputタグに対して、「piyo」を入力する。

<div class="inputs">
  <input class="radio" type="radio" value="hoge">
  <input class="radio" type="radio" value="fuga">
  <input type="text">
</div>
first("div.inputs > input[type='text']").set("piyo")

参考文献

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
14