public class ImitateSelectFile { public void Select(HtmlElement htmlEle, string fileFullPath) { htmlEle.Focus(); SendKeys.Send("{Tab}"); SendKeys.Send(" "); DelayAndOperateDialog(fileFullPath); } Random rnd = new Random(); void DelayAndOperateDialog(string fileFullPath) { BackgroundWorker b = new BackgroundWorker(); b.RunWorkerCompleted += new RunWorkerCompletedEventHandler(b_RunWorkerCompleted); b.DoWork += new DoWorkEventHandler(b_DoWork); b.RunWorkerAsync(fileFullPath); } void b_DoWork(object sender, DoWorkEventArgs e) { Thread.Sleep(3000); e.Result = e.Argument; } void b_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { SendKeys.Send(e.Result as string); SendKeys.Send("{Enter}"); } }
public partial class Form1 : Form { public Form1() { InitializeComponent(); } void init() { var aa =webBrowser1.Document; HtmlElement elefile = aa.GetElementById("f_test"); ImitateSelectFile temobj = new ImitateSelectFile(); temobj.Select(elefile, "D:\NottulnHerbst_ROW11202790843_1920x1080.jpg"); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //init(); } private void button1_Click(object sender, EventArgs e) { init(); var aa = webBrowser1.Document; var bb= aa.GetElementById("f_test"); var cc = bb; } }