Skip to content

Commit f2456ca

Browse files
committed
SetAttributeValue
1 parent 7b14c83 commit f2456ca

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ public interface IWebBrowser
2828
Task<BrowserActionResult> CloseCurrentPage(MessageInfo message);
2929
Task<BrowserActionResult> SendHttpRequest(MessageInfo message, HttpRequestParams actionParams);
3030
Task<BrowserActionResult> GetAttributeValue(MessageInfo message, ElementLocatingArgs location);
31+
Task<BrowserActionResult> SetAttributeValue(MessageInfo message, ElementLocatingArgs location);
3132
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,25 @@ public async Task<BrowserActionResult> GetAttributeValue(MessageInfo message, El
1919
Body = value ?? string.Empty
2020
};
2121
}
22+
23+
public async Task<BrowserActionResult> SetAttributeValue(MessageInfo message, ElementLocatingArgs location)
24+
{
25+
var page = _instance.GetPage(message.ContextId);
26+
ILocator locator = page.Locator(location.Selector);
27+
var elementCount = await locator.CountAsync();
28+
29+
if (elementCount > 0)
30+
{
31+
foreach (var element in await locator.AllAsync())
32+
{
33+
var script = $"element => element.{location.AttributeName} = '{location.AttributeValue}'";
34+
var result = await locator.EvaluateAsync(script);
35+
}
36+
}
37+
38+
return new BrowserActionResult
39+
{
40+
IsSuccess = true
41+
};
42+
}
2243
}

0 commit comments

Comments
 (0)