Skip to content

Commit 381db3e

Browse files
committed
Add SendKeys overload with delay; clean up using directives
A new overload of the SendKeys method has been added to the G4.WebDriver.Remote.Uia namespace in the UiaDriver.cs file. This method allows sending each character of the specified text as a key input with a delay between each keystroke. The method takes two parameters: text (the text to be sent as key inputs) and delay (the delay to wait between sending each key). In the UiaDriverTests.cs file, several using directives have been removed: G4.WebDriver.Extensions, System, and System.Threading.
1 parent f448555 commit 381db3e

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/G4.WebDriver.Remote.Uia/UiaDriver.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,25 @@ public void SendKeys(string text)
253253
SendKeys(repeat: 1, text);
254254
}
255255

256+
/// <summary>
257+
/// Sends each character of the specified text as a key input with a delay between each keystroke.
258+
/// </summary>
259+
/// <param name="text">The text to be sent as key inputs.</param>
260+
/// <param name="delay">The delay to wait between sending each key.</param>
261+
public void SendKeys(string text, TimeSpan delay)
262+
{
263+
// Iterate through each character in the provided text.
264+
foreach (var character in text)
265+
{
266+
// Send the current character as a key input.
267+
// 'repeat: 1' indicates that the key is sent once.
268+
SendKeys(repeat: 1, text: $"{character}");
269+
270+
// Wait for the specified delay before sending the next key.
271+
Thread.Sleep(delay);
272+
}
273+
}
274+
256275
/// <summary>
257276
/// Sends text input to the WebDriver server multiple times.
258277
/// </summary>

src/G4.WebDriver.Tests/UiaDriverTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
using G4.WebDriver.Models;
2-
using G4.WebDriver.Extensions;
32
using G4.WebDriver.Remote.Uia;
43

54
using Microsoft.VisualStudio.TestTools.UnitTesting;
65

7-
using System;
86
using System.IO;
9-
using System.Threading;
107

118
namespace G4.WebDriver.Tests
129
{

0 commit comments

Comments
 (0)