Deleting content from text field with Capybara

After struggling with this, I asked a coworker and the solution was to use the following:

fill_in(locator, with: "")

So, for example:

fill_in "Name", with: ""

This makes perfect sense and is probably intuitive to many, but I was stumped and couldn't find an answer on SO so I thought I would post about it in case it helps anyone.


you can use the native selenium bindings to clear an input field without filling in an empty string

element = find('locator')
element.native.clear

I prefer this option rather than fill_in.

Also if you think about it fill in is limited to find your locator by label or name so if it doesn't have a label or name you still have to use find


For me only this solution worked:

fill_in('Foo', with: 'bar', fill_options: { clear: :backspace })

I have Vue.js on frontend.