forked from SciSharp/BotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeleniumWebDriver.DoAction.cs
More file actions
42 lines (38 loc) · 1.24 KB
/
SeleniumWebDriver.DoAction.cs
File metadata and controls
42 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using OpenQA.Selenium.Interactions;
namespace BotSharp.Plugin.Selenium.Drivers;
public partial class SeleniumWebDriver
{
public async Task DoAction(MessageInfo message, ElementActionArgs action, BrowserActionResult result)
{
var driver = await _instance.InitInstance(message.ContextId);
IWebElement element = default;
if (result.Selector.StartsWith("//"))
{
element = driver.FindElement(By.XPath(result.Selector));
}
else
{
element = driver.FindElement(By.CssSelector(result.Selector));
}
if (action.Action == BroswerActionEnum.Click)
{
if (action.Position == null)
{
element.Click();
}
else
{
var size = element.Size;
var actions = new Actions(driver);
actions.MoveToElement(element)
.MoveByOffset((int)action.Position.X - size.Width / 2, (int)action.Position.Y - size.Height / 2)
.Click()
.Perform();
}
}
else if (action.Action == BroswerActionEnum.InputText)
{
element.SendKeys(action.Content);
}
}
}