[英]how do I submit a form in a WebBrowser control?
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? 如何通过C#代码提交? I tried something:
我尝试了一些:
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.
提前致谢。
Try this: 尝试这个:
HtmlElement loBtn = (HtmlElement)loWebBrowser.Document.GetElementById("btnSubmit");
loBtn .InvokeMember("click");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.