Removing content from a text box using Capybara

I am writing a script that fills Capybara text fields, but before filling in the fields I want the fields to be empty and this text should not be autocomplete. Basically, I'm looking for the opposite

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

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

+13
source share
5 answers

After dealing with this, I asked a colleague and the solution was to use the following:

 fill_in(locator, with: "") 

So for example:

 fill_in "Name", with: "" 

This makes sense and is probably intuitive for many, but I was at a dead end and couldn't find an answer to SO, so I thought I would post it in case it helps anyone.

+12
source

you can use your own selenium bindings to clear the input field without filling in an empty line

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

I prefer this option fill_in .

Also, if you think about it, fill it in to find your locator by label or name, so if it does not have a label or name, you still have to use find

+8
source

For me, only this solution worked:

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

I have Vue.js on the web interface.

+7
source

For React, you must do more than that. fill_in field, with: '' makes native.clear . Which is not very good with React. Like not fill_in field, with: 'some text' . Since it does arguments[0].value = '' before entering text.

I ran into problems with react-datetime . I decided that this is:

 def fill_in_react_datetime n, options with = options[:with] == '' ? '' : format_date(options[:with]) fill_in n, with: with, fill_options: {clear: [[:control, 'a'], :delete]} end 
+3
source

A solution that works for me and has always been reliable:

 field = find('locator') field.value.length.times { field.send_keys [:backspace]} } 

In terms of Capybara imitating user behavior, this seems correct to me too.

0
source

Source: https://habr.com/ru/post/947350/


All Articles