Merge pull request #7 from AnonymousDotNet/lida_dev
修改Locator匹配到多个时取第一个值
This commit is contained in:
commit
6bba847592
|
|
@ -12,6 +12,11 @@ public class ElementActionArgs
|
|||
|
||||
public string? PressKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Locator option
|
||||
/// </summary>
|
||||
public bool FirstIfMultipleFound { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Wait time in seconds
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -13,11 +13,24 @@ public partial class PlaywrightWebDriver
|
|||
|
||||
ILocator locator = page.Locator(result.Selector);
|
||||
var count = await locator.CountAsync();
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
Serilog.Log.Error($"Element not found: {result.Selector}");
|
||||
return;
|
||||
}
|
||||
else if (count > 1)
|
||||
{
|
||||
if(!action.FirstIfMultipleFound)
|
||||
{
|
||||
Serilog.Log.Error($"Multiple eElements were found: {result.Selector}");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
locator = page.Locator(result.Selector).First;// 匹配到多个时取第一个,否则当await locator.ClickAsync();匹配到多个就会抛异常。
|
||||
}
|
||||
}
|
||||
|
||||
if (action.Action == BroswerActionEnum.Click)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue