SetAttributeValue
This commit is contained in:
parent
7b14c8375d
commit
f2456caf35
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue