Skip to content

Commit d4f9e1c

Browse files
authored
Merge pull request #1078 from yileicn/master
modify LocateElement logger level
2 parents 2e2f389 + bb0be15 commit d4f9e1c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ElementLocatingArgs
3030

3131
public bool FailIfMultiple { get; set; }
3232
[JsonPropertyName("ignore_if_not_found")]
33-
public bool IgnoreIfNotFound { get; set; }
33+
public bool IgnoreIfNotFound { get; set; } = true;
3434

3535
/// <summary>
3636
/// Draw outline around the element

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,35 @@ public async Task<BrowserActionResult> LocateElement(MessageInfo message, Elemen
2323
}
2424
ILocator locator = page.Locator("body");
2525
int count = 0;
26+
var keyword = string.Empty;
2627

2728
// check if selector is specified
2829
if (location.Selector != null)
2930
{
31+
keyword = location.Selector;
3032
locator = locator.Locator(location.Selector);
3133
count = await locator.CountAsync();
3234
}
3335

3436
if (location.Tag != null)
3537
{
38+
keyword = location.Tag;
3639
locator = page.Locator(location.Tag);
3740
count = await locator.CountAsync();
3841
}
3942

4043
// try attribute
4144
if (!string.IsNullOrEmpty(location.AttributeName))
4245
{
43-
locator = locator.Locator($"[{location.AttributeName}='{location.AttributeValue}']");
46+
keyword = $"[{location.AttributeName}='{location.AttributeValue}']";
47+
locator = locator.Locator(keyword);
4448
count = await locator.CountAsync();
4549
}
4650

4751
// Retrieve the page raw html and infer the element path
4852
if (!string.IsNullOrEmpty(location.Text))
4953
{
54+
keyword = location.Text;
5055
var text = location.Text.Replace("(", "\\(").Replace(")", "\\)");
5156
var regexExpression = location.MatchRule.ToLower() switch
5257
{
@@ -69,6 +74,7 @@ public async Task<BrowserActionResult> LocateElement(MessageInfo message, Elemen
6974

7075
if (location.Index >= 0)
7176
{
77+
keyword = $"Index:{location.Index}";
7278
locator = locator.Nth(location.Index);
7379
count = await locator.CountAsync();
7480
}
@@ -77,12 +83,12 @@ public async Task<BrowserActionResult> LocateElement(MessageInfo message, Elemen
7783
{
7884
if (location.IgnoreIfNotFound)
7985
{
80-
result.Message = $"Can't locate element by keyword {location.Text} and Ignored";
86+
result.Message = $"Can't locate element by keyword {keyword} and Ignored";
8187
_logger.LogWarning(result.Message);
8288
}
8389
else
8490
{
85-
result.Message = $"Can't locate element by keyword {location.Text}";
91+
result.Message = $"Can't locate element by keyword {keyword}";
8692
_logger.LogError(result.Message);
8793
}
8894

0 commit comments

Comments
 (0)