2

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));
f.read(buffer);
} catch (Exception e) {
e.printStackTrace();
}
finally {
//Closing the file.
if (f != null) try { f.close(); } catch (IOException e) {
e.printStackTrace();
}
}
return new String(buffer);

}

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

String data;
data = readFileDataAsString(filePath)
we.clear();
we.sendKeys(data);

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

1 Answer 1

2

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];",
                     data);

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.