更改Locator取值以参数判断的方式

This commit is contained in:
AnonymousDotNet 2024-08-21 20:47:58 +08:00
parent 0dcb9f8c6e
commit 384c9334e2
2 changed files with 8 additions and 1 deletions

View file

@ -12,6 +12,8 @@ public class ElementActionArgs
public string? PressKey { get; set; }
public bool? IsFirst { get; set; }
/// <summary>
/// Wait time in seconds
/// </summary>

View file

@ -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)
{