Input tabs into textarea field - clipboard?

7 views
Skip to first unread message

Chris Hutchinson

unread,
Jun 21, 2018, 11:10:23 AM6/21/18
to Selenium Remote Driver
I need to write text containing tabs (CSV text) into a textarea

Using $element->send_keys("one\ttwo\tthree") doesn't work as each tab character is handled by tabbing between each control.

Can tabs be entered into an input field or alternatively is there a way with Remote Driver to put text into the clipboard where I can use send_keys(ctrl-V) to paste it?

Thanks,
Chris

Daniel Gempesaw

unread,
Jun 21, 2018, 11:29:01 AM6/21/18
to Selenium Remote Driver
Hmm, pressing the tab key manually in an actual browser pushes focus to the next field, when testing on this codepen. https://codepen.io/anon/pen/GGxVLJ?editors=1010#0 So, perhaps tabs cannot be entered into an input field? 

To get something into the clipboard, I think you'd need to do send Ctrl-C first, I believe the Selenium::Remote::WDKeys and `send_keys` should help, although you'd still need to copy the text-with-tabs from somewhere - perhaps a separate fixture html page with the content preloaded in a text area? lol... https://metacpan.org/pod/Selenium::Remote::WebElement#send_keys

Chris Hutchinson

unread,
Jun 21, 2018, 10:20:58 PM6/21/18
to Selenium Remote Driver
A solution turned out to be using execute_script to write the text into the input field. Because we have jQuery I used


$selenium
->execute_script(qq{
       
var txt = arguments[0];

        jQuery
("#$target_id").html(txt);
   
}, $text);



Reply all
Reply to author
Forward
0 new messages