0

我有这个代码:

<input type="button" onmousedown="IamTyping(0);" style="font-size:16px;" value="enter">

并在 C# 中尝试过:

GeckoInputElement enter = new GeckoInputElement(myBrowser.Document.GetElementByTagName("input").DomObject);
enter.click();

C#没有任何错误,但它不起作用!

4

1 回答 1

2

试试下面的代码

GeckoInputElement enter = (GeckoInputElement)myBrowser.Document.GetElementsByTagName("input")
    .First(inp => ((GeckoInputElement)inp).Value == "enter");

DomEventArgs ev = browser.Document.CreateEvent("MouseEvent");
ev.DomEvent.InitEvent(new nsAString("mousedown"), true, true);
enter.GetEventTarget().DispatchEvent(ev);

ev = browser.Document.CreateEvent("MouseEvent");
ev.DomEvent.InitEvent(new nsAString("mouseup"), true, true);
enter.GetEventTarget().DispatchEvent(ev);

enter.click();
于 2014-07-15T10:04:29.490 回答