IgnoreIfNotFound

This commit is contained in:
Haiping Chen 2024-08-31 07:03:25 -05:00
parent 2e5abe50ea
commit f6651b5d33
4 changed files with 26 additions and 16 deletions

View file

@ -26,6 +26,7 @@ public class ElementLocatingArgs
public bool Parent { get; set; }
public bool FailIfMultiple { get; set; }
public bool IgnoreIfNotFound { get; set; }
/// <summary>
/// Draw outline around the element

View file

@ -12,5 +12,5 @@ public class MessageInfo : ICacheKey
public string StepId { get; set; } = Guid.NewGuid().ToString();
public string GetCacheKey()
=> $"{nameof(MessageInfo)}-{AgentId}-{UserId}-{ContextId}-{MessageId}-{TaskId}";
=> $"{nameof(MessageInfo)}-{ContextId}";
}

View file

@ -164,22 +164,22 @@ public class PlaywrightInstance : IDisposable
Serilog.Log.Warning($"Response status: {e.Status} {e.StatusText}, OK: {e.Ok}");
}
var result = new WebPageResponseData
{
Url = e.Url.ToLower(),
PostData = e.Request?.PostData ?? string.Empty,
ResponseData = JsonSerializer.Serialize(json),
ResponseInMemory = responseInMemory
};
if (responseContainer != null && responseInMemory)
{
responseContainer.Add(result);
}
var webPageResponseHooks = _services.GetServices<IWebPageResponseHook>();
foreach (var hook in webPageResponseHooks)
{
var result = new WebPageResponseData
{
Url = e.Url.ToLower(),
PostData = e.Request?.PostData ?? string.Empty,
ResponseData = JsonSerializer.Serialize(json),
ResponseInMemory = responseInMemory
};
if (responseContainer != null && responseInMemory)
{
responseContainer.Add(result);
}
hook.OnDataFetched(message, result);
}
}

View file

@ -68,8 +68,17 @@ public partial class PlaywrightWebDriver
if (count == 0)
{
result.Message = $"Can't locate element by keyword {location.Text}";
_logger.LogError(result.Message);
if (location.IgnoreIfNotFound)
{
result.Message = $"Can't locate element by keyword {location.Text} and Ignored";
_logger.LogWarning(result.Message);
}
else
{
result.Message = $"Can't locate element by keyword {location.Text}";
_logger.LogError(result.Message);
}
}
else if (count == 1)
{