使用Capybara,我将如何覆盖现有的字段值? [英] Using Capybara how would I would I overwrite an existing field value?

查看:59
本文介绍了使用Capybara,我将如何覆盖现有的字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Capybara在页面上测试表单,该表单的现有值已填写在表单的字段中。我想测试是否能够将新值放入字段中并使用新值提交表单。

I am currently testing a form on a page with Capybara that has existing values filled out in the form's fields. I want to test being able to put new values into the fields and submitting the form with the new values.

当我尝试使用Capybara的fill_in方法时,它将忽略具有以下内容的字段:现有值。反正是在Capybara中用现有值覆盖字段吗?

When I try using Capybara's fill_in method it ignores the fields that have existing values. Is there anyway to overwrite fields with existing values in Capybara?

我将包括以下表格:

<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>

我尝试过的水豚代码是:

The Capybara code I've tried is:

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

我也尝试过使用评级字段类似的方法,因为评级是文本字段,而注释是文本区域,但是我仍然不能改变它。

I've also tried a similar approach with the rating field since the rating is a text field and the comment is a text area, but I still can't get it to change.

推荐答案

在XSLT表达式中使用find应该可以解决问题

using find with XSLT expression should do the trick

find(:xpath, "//input[@id='field_with_default_value_id']").set "my value"

这篇关于使用Capybara,我将如何覆盖现有的字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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