Search code examples
seleniumcapybarasaucelabs

how to instantly set/send_keys a textarea in capybara


I need to instantly fill a textarea with a very long string for testing purposes.

set/send_keys simulates typing and is too slow for Sauce Labs causing time outs.

Is there a way to instantly fill a textarea in Capybara?


Solution

  • The only way to instantly do it would be using execute_script to set the value via JS

    element = find('textarea') # however you locate the element
    execute_script('arguments[0].value = arguments[1]', element, text_to_set)
    

    Note: this won't trigger all the events a user would generate when inputting into the textarea