C# WebBrowser Control FileUpload Dialog Not Closing all the Time -
i using webbrowser control automated testing. problem - not time - when testing uploading images, file upload dialog box not close , the program "hangs" , waits manual input, defeats purpose of whole automated process. want "force" close of dialog box, have been unable figure out. or direction appreciated.
the thing realize code works some of time, not all of time. need figuring out how make code work of time.
here code:
async task populateinputfile(system.windows.forms.htmlelement file, string fname) { file.focus(); // delay execution of sendkey 500ms let choose file dialog show var sendkeytask = task.delay(5000).continuewith((_) => { // gets executed when dialog visible //sendkeys.send(fname + "{enter}"); //presskey(keys.space, false); sendkeys.sendwait(fname); presskey(keys.enter, false); }, taskscheduler.fromcurrentsynchronizationcontext()); file.invokemember("click"); // shows dialog await sendkeytask; // delay continuation 500ms let choose file dialog hide await task.delay(5000); } async task populate(string fname) { var elements = webbrowser.document.getelementsbytagname("input"); foreach (system.windows.forms.htmlelement file in elements) { if (file.getattribute("name") == "file") { this.activate(); this.bringtofront(); file.focus(); await populateinputfile(file, fname); file.removefocus(); } } }
not answer, may turn answer later. are use sure focus inside ie "choose file upload" dialog, when sendkeys? use following verify that, put code below task.delay(4000) continuewith , check output debug.print.
static class win32 { [dllimport("user32.dll", charset = charset.auto, setlasterror = true)] public static extern int getwindowtext(intptr hwnd, system.text.stringbuilder lpstring, int nmaxcount); [dllimport("user32.dll")] public static extern intptr getforegroundwindow(); } private async void form1_load(object sender, eventargs ev) { await task.delay(4000); var currentwindow = new system.text.stringbuilder(1024); win32.getwindowtext(win32.getforegroundwindow(), currentwindow, currentwindow.capacity); debug.print("currently focused window: \"{0}\"", currentwindow); }
Comments
Post a Comment