Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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)

share|improve this question

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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