From f2456caf35c0b343b695e1b0eb28ada2d6b68785 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Sat, 28 Dec 2024 01:20:48 +0000 Subject: [PATCH] SetAttributeValue --- .../Browsing/IWebBrowser.cs | 1 + .../PlaywrightWebDriver.GetAttributeValue.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs index ff2c4a7d..9386dd8a 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs @@ -28,4 +28,5 @@ public interface IWebBrowser Task CloseCurrentPage(MessageInfo message); Task SendHttpRequest(MessageInfo message, HttpRequestParams actionParams); Task GetAttributeValue(MessageInfo message, ElementLocatingArgs location); + Task SetAttributeValue(MessageInfo message, ElementLocatingArgs location); } diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GetAttributeValue.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GetAttributeValue.cs index 035bcf3b..ef266d08 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GetAttributeValue.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GetAttributeValue.cs @@ -19,4 +19,25 @@ public partial class PlaywrightWebDriver Body = value ?? string.Empty }; } + + public async Task SetAttributeValue(MessageInfo message, ElementLocatingArgs location) + { + var page = _instance.GetPage(message.ContextId); + ILocator locator = page.Locator(location.Selector); + var elementCount = await locator.CountAsync(); + + if (elementCount > 0) + { + foreach (var element in await locator.AllAsync()) + { + var script = $"element => element.{location.AttributeName} = '{location.AttributeValue}'"; + var result = await locator.EvaluateAsync(script); + } + } + + return new BrowserActionResult + { + IsSuccess = true + }; + } }