So I'm currently writing this script that will automate a simple, monotonous task using the Selenium Internet Explorer driver in C#.
Everything works great, but it is a tad bit slow at one point in the script and I'm wondering if there is a quicker way available to do what I want.
The point in question is when I have to fill out a textbox with a lot of information. This textbox will be filled sometimes up to 10,000 lines where each line never exceeds 20 characters.
However, the following approach is very slow...
// process sample file using LINQ query
var items = File.ReadAllLines(sampleFile).Select(a => a.Split(',').First());
// Process the items to be what we want to add to the textbox
var stringBuilder = new StringBuilder();
foreach (var item in items)
{
stringBuilder.Append(item + Environment.NewLine);
}
inputTextBox.SendKeys(stringBuilder.ToString());
Is there any to just set the value of the textbox to what I want? Or is this a bottleneck?
Thank you for your time and patience!
To avoid using SendKeys, you could use IJavaScriptExecutor to set the value directly. Something along these lines:
So as suggested by Richard - I ended up using
IJavaScriptExecutor
.The exact solution was to replace the call to
SendKeys
in the following line of code:With this line of code:
Casting my
InternetExplorerDriver
object to theIJavaScriptExecutor
interface in order to reach the explicitly implemented interface memberExecuteScript
and then making the call to that member with the arguments above did the trick.