From 3a255091b4a2946ed2269749a3dd3194f762f829 Mon Sep 17 00:00:00 2001 From: Haiping Chen <101423@smsassist.com> Date: Wed, 14 Feb 2024 17:11:24 -0600 Subject: [PATCH] Add atribute search for input user text --- .../PlaywrightWebDriver.InputUserText.cs | 41 +++++++++++-------- .../functions.json | 8 ++++ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.InputUserText.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.InputUserText.cs index 08a84b39..7ef1f6f5 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.InputUserText.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.InputUserText.cs @@ -8,18 +8,31 @@ public partial class PlaywrightWebDriver { await _instance.Wait(actionParams.ConversationId); + var page = _instance.GetPage(actionParams.ConversationId); + ILocator locator = default; + int count = 0; + + // try attribute + if (count == 0 && !string.IsNullOrEmpty(actionParams.Context.AttributeName)) + { + locator = page.Locator($"[{actionParams.Context.AttributeName}='{actionParams.Context.AttributeValue}']"); + count = await locator.CountAsync(); + } + // Find by text exactly match - var elements = _instance.GetPage(actionParams.ConversationId) - .GetByRole(AriaRole.Textbox, new PageGetByRoleOptions + if (count == 0) + { + locator = page.GetByRole(AriaRole.Textbox, new PageGetByRoleOptions { Name = actionParams.Context.ElementText }); - var count = await elements.CountAsync(); + count = await locator.CountAsync(); + } + if (count == 0) { - elements = _instance.GetPage(actionParams.ConversationId) - .GetByPlaceholder(actionParams.Context.ElementText); - count = await elements.CountAsync(); + locator = page.GetByPlaceholder(actionParams.Context.ElementText); + count = await locator.CountAsync(); } if (count == 0) @@ -30,22 +43,18 @@ public partial class PlaywrightWebDriver html, actionParams.Context.ElementText, actionParams.MessageId); - elements = Locator(actionParams.ConversationId, htmlElementContextOut); - count = await elements.CountAsync(); + locator = Locator(actionParams.ConversationId, htmlElementContextOut); + count = await locator.CountAsync(); } - - if (count == 0) - { - - } - else if (count == 1) + + if (count == 1) { try { - await elements.FillAsync(actionParams.Context.InputText); + await locator.FillAsync(actionParams.Context.InputText); if (actionParams.Context.PressEnter.HasValue && actionParams.Context.PressEnter.Value) { - await elements.PressAsync("Enter"); + await locator.PressAsync("Enter"); } // Triggered ajax diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions.json index b2a02c21..c788a505 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions.json +++ b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions.json @@ -92,6 +92,14 @@ "press_enter": { "type": "boolean", "description": "whether to press Enter key" + }, + "attribute_name": { + "type": "string", + "description": "attribute name in the element" + }, + "attribute_value": { + "type": "string", + "description": "attribute value in the element" } }, "required": [ "element_text", "input_text" ]