2024-03-08 13:17:36 +00:00
|
|
|
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
|
|
|
|
|
|
|
|
|
|
public partial class PlaywrightWebDriver
|
|
|
|
|
{
|
|
|
|
|
public async Task DoAction(MessageInfo message, ElementActionArgs action, BrowserActionResult result)
|
|
|
|
|
{
|
2024-04-09 03:38:56 +00:00
|
|
|
var page = _instance.GetPage(message.ContextId);
|
2024-03-08 13:17:36 +00:00
|
|
|
ILocator locator = page.Locator(result.Selector);
|
|
|
|
|
|
2024-04-08 15:09:08 +00:00
|
|
|
if (action.Action == BroswerActionEnum.Click)
|
2024-03-08 13:17:36 +00:00
|
|
|
{
|
2024-04-16 04:48:22 +00:00
|
|
|
if (action.Position == null)
|
|
|
|
|
{
|
|
|
|
|
await locator.ClickAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await locator.ClickAsync(new LocatorClickOptions
|
|
|
|
|
{
|
|
|
|
|
Position = new Position
|
|
|
|
|
{
|
|
|
|
|
X = action.Position.X,
|
|
|
|
|
Y = action.Position.Y
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-03-08 13:17:36 +00:00
|
|
|
}
|
2024-04-08 15:09:08 +00:00
|
|
|
else if (action.Action == BroswerActionEnum.InputText)
|
|
|
|
|
{
|
|
|
|
|
await locator.FillAsync(action.Content);
|
2024-05-17 23:45:18 +00:00
|
|
|
|
|
|
|
|
if (action.PressKey != null)
|
|
|
|
|
{
|
|
|
|
|
await locator.PressAsync(action.PressKey);
|
|
|
|
|
}
|
2024-04-08 15:09:08 +00:00
|
|
|
}
|
2024-06-02 02:15:47 +00:00
|
|
|
else if (action.Action == BroswerActionEnum.Typing)
|
|
|
|
|
{
|
|
|
|
|
await locator.PressSequentiallyAsync(action.Content);
|
|
|
|
|
if (action.PressKey != null)
|
|
|
|
|
{
|
|
|
|
|
await locator.PressAsync(action.PressKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-08 13:17:36 +00:00
|
|
|
}
|
|
|
|
|
}
|