Serhii Kaihorodov
Serhii Kaihorodov

Reputation: 91

Ruby: Capybara: How to fill text field with some text without clearing previously entered text in the field

I need to add some text into the text field that already contains text. When I use fill_in or set functions - it clears previously entered text. So how to add text into text box without clearing previously entered data in it?

Upvotes: 0

Views: 1815

Answers (3)

Thomas Walpole
Thomas Walpole

Reputation: 49890

Since you're using Selenium you can do

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

or

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

Upvotes: 1

Paul Fioravanti
Paul Fioravanti

Reputation: 16793

Try using Capybara::Node::Element#send_keys on your field in question to append more text to it. For example:

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

Upvotes: 0

koffeinfrei
koffeinfrei

Reputation: 2045

field = find_field 'Text field'
field.set("#{field.value} and something more...")

Upvotes: 1

Related Questions