我有这段代码:
<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#没有任何错误,但它不起作用!
答案 0 :(得分:1)
尝试以下代码
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();