diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs index b50f2366..a8b5af51 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs @@ -36,4 +36,5 @@ public class ElementLocatingArgs /// public bool Highlight { get; set; } public string HighlightColor { get; set; } = "red"; + public bool IsImage { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs index 8695fc5c..e9b4004e 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs @@ -17,6 +17,18 @@ public partial class PlaywrightWebDriver ILocator locator = page.Locator("body"); int count = 0; + if (location.IsImage) + { + var handle = await page.QuerySelectorAsync("img"); + byte[]? imageBytes = handle != null ? await handle.ScreenshotAsync() : null; + string? body = null; + if (imageBytes?.Any() == true) + { + body = Convert.ToBase64String(imageBytes); + } + return new BrowserActionResult { IsSuccess = true, Body = body }; + } + // check if selector is specified if (location.Selector != null) {