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

35 lines
1.1 KiB
C#
Raw Normal View History

2024-01-03 19:40:41 +00:00
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
public partial class PlaywrightWebDriver
{
private readonly IServiceProvider _services;
private readonly PlaywrightInstance _instance;
2024-01-23 23:14:57 +00:00
public PlaywrightInstance Instance => _instance;
2024-01-03 19:40:41 +00:00
public PlaywrightWebDriver(IServiceProvider services, PlaywrightInstance instance)
{
_services = services;
_instance = instance;
}
2024-01-27 14:58:51 +00:00
private ILocator Locator(HtmlElementContextOut context)
{
ILocator element = default;
if (!string.IsNullOrEmpty(context.ElementId))
{
// await _instance.Page.WaitForSelectorAsync($"#{htmlElementContextOut.ElementId}", new PageWaitForSelectorOptions { Timeout = 3 });
element = _instance.Page.Locator($"#{context.ElementId}");
}
else
{
if (context.Index < 0)
{
throw new Exception($"Can't locate the web element {context.Index}.");
}
element = _instance.Page.Locator(context.TagName).Nth(context.Index);
}
return element;
}
2024-01-03 19:40:41 +00:00
}