Reputation: 2526
I want to send multi-line strings to the input field using selenium. The string may have multiple line(more than 100). Sammple of string is like:
String text = "this is line1\nthis is line2\n ......\nthis is line100";
I tried to input the string in the input text box of form using sendKeys(text) but it is inputting the text line by line.
webElement.sendKeys(text);
It is taking too much time to input the text in the input box. Is there any way to sendKeys with multiple lines string at once in selenium?
Upvotes: 0
Views: 1500
Reputation: 2526
I found the solution by copying and pasting the text from the clipboard.
import java.awt.datatransfer.StringSelection;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
StringSelection stringSelection= new StringSelection(jdText);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
webElement.sendKeys(Keys.CONTROL+"v");
Upvotes: 1