Question: I'm using WatiN 2.1.0 (C#) with IE 9 on Windows 7 64 bit.

My problem is that calling this function

```
ie.FileUpload(Find.ByName(someRegExp)).Set(fileName);

```

is extremely slow.  

I mean object is nicely found. This code opens file dialog, but it starts to type file name after really long time, about 3 to 5 minutes, much longer then WatiNs timeouts. After this rest of the test is working as it should.

Is there some cure for this? This big delay is very annoying and when there is more test cases with file uploads it significantly extends test duration.

Answer: 
I had a slightly simpler solution (again relying on automation, but only for selecting the file)
I used .ClickNoWait() on the file input which did not cause the browser to hang.

I then wrote an extension method to set the file I want to select:

```
public static void UploadFile(this Browser browser, string uploadPath)
{
    var trw = new TreeWalker(Condition.TrueCondition);
    var mainWindowElement = trw.GetParent(AutomationElement.FromHandle(browser.hWnd));

    // Wait for the dialog to open
    Thread.Sleep(1000);

    // Get the select dialog
    var selectDialogElement = mainWindowElement.FindFirst(TreeScope.Descendants, 
        new PropertyCondition(AutomationElement.NameProperty, "Choose File to Upload"));

    // Get the file name box and set the path
    var selectTextElement = selectDialogElement.FindFirst(
        TreeScope.Descendants,
        new AndCondition(new PropertyCondition(AutomationElement.NameProperty, "File name:"),
            new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)));
    var selectValue = (ValuePattern)selectTextElement.GetCurrentPattern(ValuePattern.Pattern);
    selectValue.SetValue(uploadPath);

    // Get the open button and click it
    var openButtonElement = selectDialogElement.FindFirst(TreeScope.Descendants,
        new AndCondition(new PropertyCondition(AutomationElement.NameProperty, "Open"),
            new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)));
    var openButtonClick = (InvokePattern)openButtonElement.GetCurrentPattern(InvokePattern.Pattern);
    openButtonClick.Invoke();
}

```

Example Usage:

```
var browser = (IE)Document.DomContainer;     
Document.FileUpload(Find.BySelector("#FileUpload")).ClickNoWait();
browser.UploadFile("c:\\myfile.txt");
Document.Button(Find.BySelector("#submit")).Click();

```

The UIAutomation will take over from the call UploadFile(filepath) and will find the dialog window, and fill in the form as if the user did it.
I also experienced 3 to 5 minute delays before WatiN started typing the file name in the file upload dialog box.

This seems to happen to me whenever the developer tools pane is open in IE. When it is not open, typing starts right away.

Prompts about default browser and similar popups also seems to cause the delay.