Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting content from text field with Capybara

I'm writing a script that fills out text fields with Capybara, but prior to filling out the fields, I want to ensure that the fields are empty and that text is not autofilled. Basically, I'm looking for the opposite of

(Object) fill_in(locator, options = {})    #empty_content_of? delete?

found here: http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions. Advice?

like image 649
aceofbassgreg Avatar asked Jun 15 '13 03:06

aceofbassgreg


3 Answers

For me only this solution worked:

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

I have Vue.js on frontend.

like image 182
Yurii Halapup Avatar answered Nov 13 '22 23:11

Yurii Halapup


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.

like image 18
aceofbassgreg Avatar answered Nov 13 '22 21:11

aceofbassgreg


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

like image 14
skaliber Avatar answered Nov 13 '22 23:11

skaliber