How to set the value of a text field right away using webdriver?

I use Cucumber, watir-webdriver, page-object and jruby. I am writing a method in a page class that injects a value into a text area. I use the generated method in stone page-object, which, under the hood, calls the Watir-Webdriver method set, which in turn calls the send_keyselement.

In any case, the problem for me is that I am trying to add a VERY BIG STRING (to check the maximum size properties for a valid object). This is 4000 characters and takes a noticeable amount of time to enter.

It would be great if there was a way to simply insert the entire line into the text area at once. Is there a way to do this with the technologies that I have? These .. JRuby, watir-webdriver, page-object (which really just passes watir-webdriver). I believe that under the hood is selenium-webdriver, which in any case interacts with the browser driver.

So far, I have not found a path, ultimately using send_keys, which basically sends one key stroke at a time, and therefore a huge character string is a pain.

+4
source share
1 answer

You can directly set the field value with execute_script.

:

<html>
  <body>
    <textarea></textarea>
  </body>
</html>

set 6-9 ( Firefox/Chrome):

input = 'a' * 4000
browser.textarea.set(input)

, execute_script, , 0,2 :

input = 'a' * 4000
field = browser.textarea
browser.execute_script('arguments[0].value = arguments[1];', field, input) 
+7

All Articles