SetAttributeValue

This commit is contained in:
Haiping Chen 2024-12-28 01:20:48 +00:00
parent 7b14c8375d
commit f2456caf35
2 changed files with 22 additions and 0 deletions

View file

@ -28,4 +28,5 @@ public interface IWebBrowser
Task<BrowserActionResult> CloseCurrentPage(MessageInfo message);
Task<BrowserActionResult> SendHttpRequest(MessageInfo message, HttpRequestParams actionParams);
Task<BrowserActionResult> GetAttributeValue(MessageInfo message, ElementLocatingArgs location);
Task<BrowserActionResult> SetAttributeValue(MessageInfo message, ElementLocatingArgs location);
}

View file

@ -19,4 +19,25 @@ public partial class PlaywrightWebDriver
Body = value ?? string.Empty
};
}
public async Task<BrowserActionResult> SetAttributeValue(MessageInfo message, ElementLocatingArgs location)
{
var page = _instance.GetPage(message.ContextId);
ILocator locator = page.Locator(location.Selector);
var elementCount = await locator.CountAsync();
if (elementCount > 0)
{
foreach (var element in await locator.AllAsync())
{
var script = $"element => element.{location.AttributeName} = '{location.AttributeValue}'";
var result = await locator.EvaluateAsync(script);
}
}
return new BrowserActionResult
{
IsSuccess = true
};
}
}