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 3849982
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:56:21+00:00 2026-05-19T16:56:21+00:00

I am testing a website using WatiN. On one of the pages I get

  • 0

I am testing a website using WatiN.
On one of the pages I get a “report” in an Iframe, within this I frame there is a link to download and save the report. But since the only way to get to the link is to use frame.Link(…) the pop-up closes immediately after opening; Code snippet below

//Click the create graph button

ie.Button(Find.ById(“ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_btnCreateGraph”)).Click();

  //Lets export the data

  ie.Div(Find.ById("colorbox"));

  ie.Div(Find.ById("cboxContent"));

  ie.Div(Find.ById("cboxLoadedContent"));

  Thread.Sleep(1000);//Used to cover performance issues

  Frame frame = ie.Frame(Find.ByName(frameNameRegex));

  for (int Count = 0; Count < 10000000; Count++) {double nothing = (Count/12); }//Do nothing I just need a short pause


  //SelectList waits for a postback which does not occur.
  try
  {

        frame.SelectList(Find.ById("rvReport_ctl01_ctl05_ctl00")).SelectByValue("Excel");

  }

  catch (Exception)

  {

       //Do nothing

  }

  //Now click export

  frame.Link(Find.ById("rvReport_ctl01_ctl05_ctl01")).ClickNoWait();

  IE ieNewBrowserWindow = IE.AttachTo<IE>(Find.ByUrl(urlRegex));

  fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(150); 

  fileDownloadHandler.WaitUntilDownloadCompleted(200);

I have tried using ie instead of frame which is why all those ie.Div’s are present.
if I use frame the pop-up window opens and closes instantly.
If I use ie I get a link not found error.
If I click on the link manually, while the test is “trying to find the link” the file will download correctly.
I have changed the code to use a different page that doe not have the frame and I still get the same problem download pop-up closes instantly.

[STAThread]

  public void TestForMeterDataExport()

  {

      // Open a new Internet Explorer window and

      // goto the website.

      IE ie = new IE("https://<URL>", true);

      FileDownloadHandler fileDownloadHandler = new FileDownloadHandler("C:\\Documents and Settings\\karnold\\Desktop\\MeterUsageReport_Large.xls");

      Regex urlRegex = new Regex("<URL>\\?Mode=true&ReportID=[a-z A-Z 0-9]{30,33}&ControlID=[a-z A-Z 0-9]{30,33}&Culture=1033&UICulture=1033&ReportStack=1&OpType=Export&FileName=BuildingMeterDataReport&ContentDisposition=OnlyHtmlInline&Format=Excel");


      //Find the Username text field and input the user ID

      ie.TextField(Find.ByName("ctl00$ContentPlaceHolder1$txtUsername")).TypeText("<Name>");


      //Find the Password text field and input the password

      ie.TextField(Find.ByName("ctl00$ContentPlaceHolder1$txtPassword")).TypeText("PASS");


      //Go ahead and login 

      ie.Button(Find.ByName("ctl00$ContentPlaceHolder1$butLogin")).Click();

      //Let's use the Reports Tab

      ie.Link(Find.ByUrl("https://<URL>")).Click(); 

      // Let's get the meter data

      ie.Link(Find.ByUrl("https://<URL>")).Click();

      //Let's choose University of 

      ie.SelectList(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_TopBoxContentPlaceHolder_ucFacility_ddlFacility")).SelectByValue("5041");

      //Set the date range for which we want to get data
      ie.TextField(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_TopBoxContentPlaceHolder_DateRangePicker1_dpBeginDate_TextBox")).TypeText("12/09/10");

      ie.TextField(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_TopBoxContentPlaceHolder_DateRangePicker1_dpEndDate_TextBox")).TypeText("12/10/10"); 

      //Click the create report button
      ie.Button(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_TopBoxContentPlaceHolder_btnSubmit")).ClickNoWait();

      //Lets export the data

      Thread.Sleep(2000);

      //SelectList waits for a postback which does not occur.

      try

      {

          ie.SelectList(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentAreaContentPlaceHolder_ContentAreaContentPlaceHolder_rvMain_ctl01_ctl05_ctl00")).SelectByValue("Excel");

      }

      catch (Exception)

      {


          ie.SelectList(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentAreaContentPlaceHolder_ContentAreaContentPlaceHolder_rvMain_ctl01_ctl05_ctl00")).FireEventNoWait("onchange");

          //fire the postback event

      }

      //Now click export
      ie.Link(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentAreaContentPlaceHolder_ContentAreaContentPlaceHolder_rvMain_ctl01_ctl05_ctl01")).ClickNoWait();

      IE ieNewBrowserWindow = IE.AttachTo<IE>(Find.ByUrl(urlRegex));

      fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(10);
      fileDownloadHandler.WaitUntilDownloadCompleted(20);

  }// close TestForMeterDataExport()

Hopefully some one can tell me what I am doing wrong. Thank you

Here is the error that I get when the program can’t find the handle maybe it will help
TestCase ‘M:WebTest.CommandLine.WatiNConsoleWebAndDB.TestForMeterDataExport’
failed: Error HRESULT E_FAIL has been returned from a call to a COM component.
System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
at SHDocVw.IWebBrowser2.get_Document()
at WatiN.Core.Native.InternetExplorer.IEBrowser.get_NativeDocument()
at WatiN.Core.Native.InternetExplorer.IEWaitForComplete.WaitForCompleteOrTimeout()
at WatiN.Core.WaitForCompleteBase.DoWait()
at WatiN.Core.DomContainer.WaitForComplete(IWait waitForComplete)
at WatiN.Core.Native.InternetExplorer.AttachToIeHelper.FinishInitializationAndWaitForComplete(IE ie, SimpleTimer timer, Boolean waitForComplete)
at WatiN.Core.Native.InternetExplorer.AttachToIeHelper.Find(Constraint findBy, Int32 timeout, Boolean waitForComplete)
at WatiN.Core.Browser.AttachTo(Type browserType, Constraint constraint, Int32 timeout)
at WatiN.Core.Browser.AttachTo(Type browserType, Constraint constraint)
at WatiN.Core.Browser.AttachTo[T](Constraint constraint)
Web+DB_test_app.cs(139,0): at WebTest.CommandLine.WatiNConsoleWebAndDB.TestForMeterDataExport()

  • 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-05-19T16:56:21+00:00Added an answer on May 19, 2026 at 4:56 pm

    Thanks to Baptiste for the pointer.

    //Set the handles and the file save as name

          FileDownloadHandler handler = new FileDownloadHandler("MeterUsageReport_Large_Iframe.xls");
    
          // add a watcher to look for the save file local
    
          ie.AddDialogHandler(handler);
    
          //Do not close dialog boxes immediately
    
          ie.DialogWatcher.CloseUnhandledDialogs = false;
    
          //create a single use instance that will be easily cleaned up and avoid having windows open after we are done with them
    
          using (new UseDialogOnce(ie.DialogWatcher, handler))
    
          {
              //Now click export
    
              frame.Link(Find.ById("rvReport_ctl01_ctl05_ctl01")).ClickNoWait();
    
              //Grab hold of the poup dialog and download the file             
              handler.WaitUntilFileDownloadDialogIsHandled(30);
              handler.WaitUntilDownloadCompleted(35);
          }
    

    Now for the fun this will only work if all of the work is done on localhost.
    if you need to hit a server that is not local and ou want to use IE well then
    2) You will need to edit the security for “trusted sites to allow scripting of downloads and Iframes.
    * a) open IE
    * b) Tools -> Internet options
    * c) Security tab.
    * d) make sure “trusted site” is highlighted
    * e) click custom level, Make sure all .Net and .Net reliant components are set to enabled.
    * f) Enable or prompt all activeX components
    * g) Enable all downloads
    * h) Enable .Net framework setup
    * i) Enable scripting of web browser controls
    * j) Enable allow websites to open windows without address’s or status bars.
    * k) Enable Launching programs or files from an Iframe.
    * l) Everything under scripting is set to enabled or prompt.
    * Just so you know, localhost is treated as a “low” security area so tests run on localhost do not need these changes.
    * Refer to http://support.microsoft.com/kb/174360

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Watir to do some automated testing for a website. This particular test
I am testing a website before i make it live and i am using
I am testing a website in Firefox 8. I am using a jQuery.post call
I'm using Jmeter to do a load testing for a website. JMeter does not
I have used this website for testing http://www.webpagetest.org and among some suggestions for optimization
I am developing a small testing website using Django 1.2 in Aptana Studio build
I am testing integrating a website to Paypal, using Web Payments standard and HTML
I am testing the security of my website. I am using the following URL
I am using form authentication inmy ASP.NET 2.0 website. Today during testing i was
I'm using Codeigniter if this makes it easier. I'm wondering if a website is

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.