【问题标题】:DotNetBrowser : Simulating ClickDotNetBrowser:模拟点击
【发布时间】:2021-01-04 09:42:39
【问题描述】:

如何在没有“onclick”标签,只有“event-action”的元素上使用 dotnetbrowser 模拟点击

【问题讨论】:

  • 您的代码在哪里,您尝试过什么?

标签: c# onclick dotnetbrowser


【解决方案1】:

你可以这样做:

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

如果需要点击 id=x123 的元素

如果对元素不起作用,您可以将鼠标点击发送到元素点:

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多