Skip to content

Commit c729fa1

Browse files
jdpurcellAutomatedTesterdiemol
authored
Fix SendKeys regressions related to multiple file uploading. (#8635)
* Fix SendKeys regressions related to multiple file uploading. * Match style of existing code. Co-authored-by: David Burns <david.burns@theautomatedtester.co.uk> Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
1 parent e810d24 commit c729fa1

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

dotnet/src/webdriver/Remote/RemoteWebElement.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.Globalization;
2424
using System.IO;
2525
using System.IO.Compression;
26+
using System.Linq;
2627
using OpenQA.Selenium.Interactions.Internal;
2728
using OpenQA.Selenium.Internal;
2829
using System.Text;
@@ -279,19 +280,18 @@ public virtual void SendKeys(string text)
279280
{
280281
throw new ArgumentNullException("text", "text cannot be null");
281282
}
283+
282284
var fileNames = text.Split('\n');
283-
var amendedText = "";
284-
foreach (var fileName in fileNames)
285+
if (fileNames.All(this.driver.FileDetector.IsFile))
285286
{
286-
if (this.driver.FileDetector.IsFile(fileName))
287-
{
288-
amendedText += this.UploadFile(fileName) + "\n";
289-
}
290-
else
291-
{
292-
amendedText = fileName + "\n";
293-
}
287+
var uploadResults = new List<string>();
288+
foreach (var fileName in fileNames)
289+
{
290+
uploadResults.Add(this.UploadFile(fileName));
291+
}
292+
text = string.Join("\n", uploadResults);
294293
}
294+
295295
// N.B. The Java remote server expects a CharSequence as the value input to
296296
// SendKeys. In JSON, these are serialized as an array of strings, with a
297297
// single character to each element of the array. Thus, we must use ToCharArray()
@@ -300,8 +300,8 @@ public virtual void SendKeys(string text)
300300
// appropriate one for spec compliance.
301301
Dictionary<string, object> parameters = new Dictionary<string, object>();
302302
parameters.Add("id", this.elementId);
303-
parameters.Add("text", amendedText);
304-
parameters.Add("value", amendedText.ToCharArray());
303+
parameters.Add("text", text);
304+
parameters.Add("value", text.ToCharArray());
305305

306306
this.Execute(DriverCommand.SendKeysToElement, parameters);
307307
}

0 commit comments

Comments
 (0)