Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8904065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:01:34+00:00 2026-06-15T02:01:34+00:00

I’m using WatiN 2.1.0 (C#) with IE 9 on Windows 7 64 bit. My

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:01:35+00:00Added an answer on June 15, 2026 at 2:01 am

    Ok, this is not a Watin solution per say, but we had the exact same problem; our file browser tests took up a lot of the total test time, and I solved it by kicking out Watin for fileuploads and instead use the (horrific) UIAutomation framework.

    Example usage:

        public CustomFileUpload FileUpload
        {
            get
            {
                return new CustomFileUpload(WebBrowser.Current.hWnd, "_Layout");
                //return Document.FileUpload(Find.ByName("file"));
            }
        }
    

    You have to add referefences to “UIAutomationClient” and “UIAutomationTypes” in your test project. And the solution below is not generic so you might have to tweak it to fit your needs.

    public class CustomFileUpload
    {
        private readonly IntPtr _browserHandle;
        private readonly string _tabHeader;
    
        public CustomFileUpload(IntPtr browserHandle, string tabHeader)
        {
            _browserHandle = browserHandle;
            _tabHeader = tabHeader;
        }
    
        public void Set(string filePath)
        {
            Automate(filePath);
        }
    
        private void Automate(string filePath)
        {
            AutomationElement browser = AutomationElement.FromHandle(_browserHandle);
    
            AutomationElement tab = FindTab(browser, _tabHeader);
    
    
            // IE10 adds the name (or value?) "Browse..." to the upload-button. Need to hack it :)
            AutomationElement uploadButton = tab.FindFirst(TreeScope.Children,
                                                                new AndCondition(
                                                                    new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button),
                                                                    new PropertyCondition(AutomationElement.NameProperty, "Browse..."))) ??
                                                                    tab.FindFirst(TreeScope.Children,
                                                            new AndCondition(
                                                                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button),
                                                                new PropertyCondition(AutomationElement.NameProperty, "")));
    
            ClickButton(uploadButton);
    
            var openFileDialog = WaitUntilOpenFileDialogAvailable();
    
            var valuePattern = FindFileNameTextBox(openFileDialog).GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
    
            if (valuePattern == null)
                throw new InvalidOperationException("Can't set the file path");
    
            valuePattern.SetValue(filePath);
    
            SetFocusToSomethingElse(browser);
    
            var okButton = WaitUntilOkButtonLoaded(openFileDialog);
    
            ClickButton(okButton);
        }
    
        private static AutomationElement FindTab(AutomationElement browser, string tabHeader)
        {
            return browser.FindFirst(TreeScope.Descendants,
                                     new AndCondition(
                                         new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane),
                                         new PropertyCondition(AutomationElement.NameProperty, tabHeader)));
        }
    
        private static void SetFocusToSomethingElse(AutomationElement elementWhichShouldNotBeSelected)
        {
            do
            {
                foreach (AutomationElement element in AutomationElement.RootElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.IsKeyboardFocusableProperty, true)))
                {
                    if (element != elementWhichShouldNotBeSelected)
                    {
                        element.SetFocus();
                        return;
                    }
                }
    
            } while (true);
        }
    
        private static AutomationElement WaitUntilOkButtonLoaded(AutomationElement openFileDialog)
        {
            AutomationElement okButton;
    
            do
            {
                okButton = openFileDialog.FindFirst(TreeScope.Children,
                                                    new AndCondition(
                                                        new PropertyCondition(AutomationElement.IsContentElementProperty, true),
                                                        new PropertyCondition(AutomationElement.IsControlElementProperty, true),
                                                        new PropertyCondition(AutomationElement.NameProperty, "Open"),
                                                        new PropertyCondition(AutomationElement.IsInvokePatternAvailableProperty, true)
                                                        ));
    
            } while (okButton == null);
    
            return okButton;
        }
    
        private static AutomationElement WaitUntilOpenFileDialogAvailable()
        {
            AutomationElement openFileDialog = null;
    
            do
            {
    
                AutomationElement openFileDialogContainer = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "Alternate Modal Top Most"));
    
                if (openFileDialogContainer != null)
                    openFileDialog = openFileDialogContainer.FindFirst(TreeScope.Children, Condition.TrueCondition);
            } while (openFileDialog == null);
    
            return openFileDialog;
        }
    
        private static void ClickButton(AutomationElement button)
        {            
            var clickPattern = button.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
    
            if (clickPattern == null)
                throw new InvalidOperationException("Can't find the buttons click pattern");
    
            clickPattern.Invoke();
        }
    
        private static AutomationElement FindFileNameTextBox(AutomationElement openFileDialog)
        {
            AutomationElement findElementToTypePathInto;
    
            do
            {
                findElementToTypePathInto = openFileDialog.FindFirst(TreeScope.Descendants, new AndCondition(new PropertyCondition(AutomationElement.NameProperty, "File name:"), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)));
            } while (findElementToTypePathInto == null);
    
            return findElementToTypePathInto;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.