【问题标题】:Ruby: Capybara: How to fill text field with some text without clearing previously entered text in the fieldRuby:Capybara:如何用一些文本填充文本字段而不清除字段中先前输入的文本
【发布时间】:2016-12-09 17:10:33
【问题描述】:

我需要在已经包含文本的文本字段中添加一些文本。 当我使用 fill_in 或 set 函数时 - 它会清除以前输入的文本。 那么如何在文本框中添加文本而不清除之前输入的数据呢?

【问题讨论】:

  • 您在 Capybara 上使用什么驱动程序?一些驱动程序对此有不同的选择(特别是硒驱动程序)。
  • 我使用 Selenium 驱动程序。

标签: ruby testing automation capybara


【解决方案1】:

因为您使用的是 Selenium,所以您可以这样做

fill_in('whatever', with: 'text to append', fill_options: {clear: :none})

field.set('whatever', clear: :none)

【讨论】:

    【解决方案2】:
    field = find_field 'Text field'
    field.set("#{field.value} and something more...")
    

    【讨论】:

      【解决方案3】:

      尝试在您的相关字段上使用Capybara::Node::Element#send_keys 以向其附加更多文本。例如:

      find('#your-text-field').send_keys("this is more text to add")
      

      【讨论】:

        猜你喜欢
        • 2013-06-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多