Search code examples
automationcapybara

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?


Solution

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