2

現在、フォームのフィールドに既存の値が入力されているカピバラのページでフォームをテストしています。フィールドに新しい値を入力し、新しい値でフォームを送信できることをテストしたいと思います。

Capybara の fill_in メソッドを使用しようとすると、既存の値を持つフィールドが無視されます。カピバラの既存の値でフィールドを上書きする方法はありますか?

以下のフォームを含めます。

<form accept-charset="UTF-8" action="/submissions/1/reviews/4" class=
  "simple_form edit_review" id="edit_review_4" method="post" novalidate="novalidate"
  name="edit_review_4">
    <div style="margin:0;padding:0;display:inline">
      <input name="utf8" type="hidden" value="&#10003;"><input name="_method" type=
      "hidden" value="put"><input name="authenticity_token" type="hidden" value=
      "gJ/KKAodeIJD8PPnRNeN4GaGb/yqvUDHrsnl9LqLP/c=">
    </div>

    <div class="input integer optional">
      <label class="integer optional control-label" for=
      "review_rating">Rating</label><input class="numeric integer optional" id=
      "review_rating" name="review[rating]" step="1" type="number" value="33">
    </div>

    <div class="input text required">
      <label class="text required control-label" for="review_comment"><abbr title=
      "required">*</abbr> Comment</label>
      <textarea class="text required" cols="40" id="review_comment" name=
      "review[comment]" rows="20">
hellofsdf
</textarea>
    </div><input class="btn" name="commit" type="submit" value="Update Review">
  </form>

私が試したカピバラコードは次のとおりです。

find(:xpath, "//*[(@id = 'review_comment')]").set "hello"

評価はテキスト フィールドであり、コメントはテキスト領域であるため、評価フィールドでも同様のアプローチを試みましたが、それでも変更できません。

4

2 に答える 2

0

phantomjs/poltergeist のような JavaScript ドライバーを使用してから、JavaScript を使用してそのような値を設定します。

page.evaluate_script("document.getElementById('#some-id').value = 'some-value'");

この質問に対する私の答えに似ています。

于 2014-02-19T21:52:34.667 に答える