Replace special symbol for match rule.

This commit is contained in:
Haiping Chen 2024-06-28 10:18:45 -05:00
parent 77977f2aa1
commit fbdd44b78d
2 changed files with 5 additions and 5 deletions

View file

@ -8,7 +8,6 @@ public class BrowserActionResult
public string Selector { get; set; }
public string Body { get; set; }
public bool IsHighlighted { get; set; }
public DateTime? ExecutedAt { get; set; } = DateTime.UtcNow;
public override string ToString()
{

View file

@ -40,12 +40,13 @@ public partial class PlaywrightWebDriver
// Retrieve the page raw html and infer the element path
if (!string.IsNullOrEmpty(location.Text))
{
var text = location.Text.Replace("(", "\\(").Replace(")", "\\)");
var regexExpression = location.MatchRule.ToLower() switch
{
"startwith" => $"^{location.Text}",
"endwith" => $"{location.Text}$",
"contains" => $"{location.Text}",
_ => $"^{location.Text}$"
"startwith" => $"^{text}",
"endwith" => $"{text}$",
"contains" => $"{text}",
_ => $"^{text}$"
};
var regex = new Regex(regexExpression, RegexOptions.IgnoreCase);
locator = locator.GetByText(regex);