how to programmatically set an input an element value inside a WebBrowser control?
如何以编程方式在WebBrowser控件中设置输入元素值?
For example, I have an HTML page, like:
例如,我有一个HTML页面,如:
<form method="post" action="...aspx" enctype="multipart/form-data" id="mainForm">
<input type="file" id="file" />
<input type="submit" id="submit" value="Submit it" />
</form>
How do I to submit it via C# code? I tried something:
如何通过C#代码提交?我试了一下:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var doc = webBrowser1.Document;
var input = doc.GetElementById("file");
input.SetAttribute("value", @"C:\foo.baa");
doc.GetElementById("mainForm").InvokeMember("submit");
}
but it does not working, the value of input is not setted and the form is not submited. I hope this is clean. Thanks in advance.
但它没有工作,输入的值没有设置,表单也没有提交。我希望这很干净。提前致谢。
2 个解决方案
#1
1
Try this:
HtmlElement loBtn = (HtmlElement)loWebBrowser.Document.GetElementById("btnSubmit");
loBtn .InvokeMember("click");
#1
1
Try this:
HtmlElement loBtn = (HtmlElement)loWebBrowser.Document.GetElementById("btnSubmit");
loBtn .InvokeMember("click");