I am facing an issue with moving large chunk of data from file to TextArea in the app.

Its taking lots of time and inputing data Line by line ...

Please find the code snippet below and suggest if something can be done to make it fast.

This is the code to read file content using streams.

public static String readFileDataAsString(String filePath) {

byte[] buffer = new byte[(int) new File(filePath).length()];
BufferedInputStream f = null;
try {
f = new BufferedInputStream(new FileInputStream(filePath));
} catch (Exception e) {
finally {
//Closing the file.
if (f != null) try { f.close(); } catch (IOException e) {
return new String(buffer);


Code to send File content to UI Field in Selenium is:

String data;
data = readFileDataAsString(filePath)

also, tried selenium.type("locator", data)

1 Answer 1


You can set the textarea's value more quickly using the executeScript method on the JavascriptExecutor interface. For example, suppose your textarea looks like this:

<textarea id='t'></textarea>

You can set its value like this:

driver.executeScript("var t = document.getElementById('t'); "+
                     "t.value = arguments[0];",

This worked for me using Firefox 10.0.2 and Selenium/WebDriver 2.20.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.