From 384c9334e29ecca56ae2a087175bfcdeac6c52da Mon Sep 17 00:00:00 2001 From: AnonymousDotNet <18776095145@163.com> Date: Wed, 21 Aug 2024 20:47:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9Locator=E5=8F=96=E5=80=BC?= =?UTF-8?q?=E4=BB=A5=E5=8F=82=E6=95=B0=E5=88=A4=E6=96=AD=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Browsing/Models/ElementActionArgs.cs | 2 ++ .../PlaywrightDriver/PlaywrightWebDriver.DoAction.cs | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementActionArgs.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementActionArgs.cs index 046187eb..37011e52 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementActionArgs.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementActionArgs.cs @@ -12,6 +12,8 @@ public class ElementActionArgs public string? PressKey { get; set; } + public bool? IsFirst { get; set; } + /// /// Wait time in seconds /// 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 08ce88e8..4a52f539 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.DoAction.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.DoAction.cs @@ -11,7 +11,12 @@ public partial class PlaywrightWebDriver return; } - ILocator locator = page.Locator(result.Selector).First;// 匹配到多个时取第一个,否则当await locator.ClickAsync();匹配到多个就会抛异常。 + ILocator locator = page.Locator(result.Selector); + if (action.IsFirst == true) + { + locator = page.Locator(result.Selector).First;// 匹配到多个时取第一个,否则当await locator.ClickAsync();匹配到多个就会抛异常。 + } + var count = await locator.CountAsync(); if (count == 0) {