From afc880e1c0ecc3a8934ef915a762e73d0659462e Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 18 Nov 2024 18:52:59 +0000 Subject: [PATCH] DelayBeforePressingKey --- .../Browsing/Models/ElementActionArgs.cs | 4 ++++ .../PlaywrightDriver/PlaywrightWebDriver.DoAction.cs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementActionArgs.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementActionArgs.cs index 2935496c..7ac03f17 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementActionArgs.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementActionArgs.cs @@ -12,6 +12,10 @@ public class ElementActionArgs public ElementPosition? Position { get; set; } + /// + /// Delay milliseconds before pressing key + /// + public int DelayBeforePressingKey { get; set; } public string? PressKey { get; set; } /// diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.DoAction.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.DoAction.cs index 93928af9..f7884beb 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.DoAction.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.DoAction.cs @@ -56,6 +56,10 @@ public partial class PlaywrightWebDriver if (action.PressKey != null) { + if (action.DelayBeforePressingKey > 0) + { + await Task.Delay(action.DelayBeforePressingKey); + } await locator.PressAsync(action.PressKey); } } @@ -64,6 +68,10 @@ public partial class PlaywrightWebDriver await locator.PressSequentiallyAsync(action.Content); if (action.PressKey != null) { + if (action.DelayBeforePressingKey > 0) + { + await Task.Delay(action.DelayBeforePressingKey); + } await locator.PressAsync(action.PressKey); } }