DotNetBrowser : Simulating Click

409 Views Asked by At

How to simulate clicking using dotnetbrowser on an element that doesn't have the "onclick" tag, only "event-action"

1

There are 1 best solutions below

0
On

you can make so:

browser.MainFrame.Document.GetElementById("x123").Click();

if need click in element where id=x123

if it`s no work with element, you can send MouseClick to element Point:

int top = browser.MainFrame.Document.GetElementById("x123").BoundingClientRect.Origin.Y;
int left = browser.MainFrame.Document.GetElementById("x123").BoundingClientRect.Origin.X;
IMouse mouse = browser.Mouse;
MouseButton mouseButton = MouseButton.Left;
Point location = new Point(left+3, top+3);

MouseMovedEventArgs moveEvent = new MouseMovedEventArgs
{
    Location = location
};

MousePressedEventArgs pressEvent = new MousePressedEventArgs
{
    Location = location,
    Button = mouseButton,
    ClickCount = 1
};

MouseReleasedEventArgs releaseEvent = new MouseReleasedEventArgs
{
    Button = mouseButton,
    ClickCount = 1,
    Location = location
};

mouse.Moved.Raise(moveEvent);
Thread.Sleep(200);
mouse.Pressed.Raise(pressEvent);
Thread.Sleep(200);
mouse.Released.Raise(releaseEvent);