在下载IE9与华廷文件 [英] Downloading a file with Watin in IE9

查看:135
本文介绍了在下载IE9与华廷文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与自动化从网站下载文件的过程中的问题。该网站有一个Java按钮,单击时,将触发一个Excel文件的下载。我使用的最新版本,华廷(V2.1)。

我设法让华廷登录到网站上,导航到相应的页面,更改参数的页面,并单击按钮开始下载。

然而,当下载完成后,将出现IE9的下载框,什么都不会发生,直到华廷timesout。

我倒是AP preciate任何建议,我不能看到下载文件,或得到它来保存文件的任何方式。即使通过Alt + S'页面,将其保存。我试着运行它通过WatinTestRecorder并不会提示保存。

 使用(VAR浏览器=新的IE(s登录))
{
    browser.AddDialogHandler(新OKDialogHandler());
    browser.AddDialogHandler(新DialogHandlerHelper());
    browser.AddDialogHandler(新ConfirmDialogHandler());
    browser.AddDialogHandler(新ReturnDialogHandlerIe9());    browser.TextField(Find.ByName(txtUserID))的TypeText(用户名)。
    browser.TextField(Find.ByName(txtPassword))的TypeText(密码)。
    。browser.Button(Find.ByName(btnLogin))点击();    browser.WaitForComplete();
    browser.GoTo(targetUri);    browser.SelectList(ctl00_phFormContent_ucOptionParam0_lst)SelectByValue(4)。    。browser.Button(Find.ByName(ctl00 $ phFormButtonBar $ btnRun))点击();
    browser.WaitForComplete();    //有些code到这里下载文件!
}


解决方案

这应当自1.1.0.4000版本的支持。该版本的发行说明不在线了( http://watin.org/documentation/ )但我发现它在谷歌的缓存(的http://svn6.assembla.com/svn/ci-samples/dotnet/watir/website/releasenotes-1-1-0-4000.html)

应该是这样的:

 使用(即IE =新的IE(someUrlToGoTo))
{
    FileDownloadHandler fileDownloadHandler =新FileDownloadHandler(fullFileName);
    ie.AddDialogHandler(fileDownloadHandler);    ie.Link(startDownloadLinkId)点击()。    fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
    fileDownloadHandler.WaitUntilDownloadCompleted(200);
}

编辑:
下面的评论后,这个答案被接受。所以我假设下code ++工程,(这是从环节采取的SourceForge在我的最后意见,注意ClickNoWait):

 使用(即IE =新的IE(someUrlToGoTo))
{
    FileDownloadHandler fileDownloadHandler =新FileDownloadHandler(fullFileName);
    ie.AddDialogHandler(fileDownloadHandler);    ie.Link(startDownloadLinkId)ClickNoWait()。    fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
    fileDownloadHandler.WaitUntilDownloadCompleted(200);
}

I'm having an issue with automating the process of downloading a file from a website. The website has a Java button, that when clicked, triggers the download of an Excel file. I'm using the most recent build of Watin (v2.1).

I've managed to get Watin to log into the website, navigate to the appropriate page, change parameters on the page, and click the button to start the download.

However, when the download has completed, the IE9 download box appears, and nothing happens, until Watin timesout.

I'd appreciate any suggestions as I can't see any way of downloading a file, or getting it to save the file. Even if it passed 'Alt+S' to the page, that would save it. I've tried running it through WatinTestRecorder and that doesn't prompt for saving.

using (var browser = new IE(sLogin))
{
    browser.AddDialogHandler(new OKDialogHandler());
    browser.AddDialogHandler(new DialogHandlerHelper());
    browser.AddDialogHandler(new ConfirmDialogHandler());
    browser.AddDialogHandler(new ReturnDialogHandlerIe9());

    browser.TextField(Find.ByName("txtUserID")).TypeText("username");
    browser.TextField(Find.ByName("txtPassword")).TypeText("password");
    browser.Button(Find.ByName("btnLogin")).Click();

    browser.WaitForComplete();  
    browser.GoTo(targetUri);

    browser.SelectList("ctl00_phFormContent_ucOptionParam0_lst").SelectByValue("4");

    browser.Button(Find.ByName("ctl00$phFormButtonBar$btnRun")).Click();
    browser.WaitForComplete();

    //Some code to download the file here!
}

解决方案

This should be supported since version 1.1.0.4000. The release notes for that version aren't online anymore (http://watin.org/documentation/), but I found it in Googles cache (http://svn6.assembla.com/svn/ci-samples/dotnet/watir/website/releasenotes-1-1-0-4000.html)

It should be something like:

using(IE ie = new IE(someUrlToGoTo))
{
    FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(fullFileName);
    ie.AddDialogHandler(fileDownloadHandler);

    ie.Link("startDownloadLinkId").Click();

    fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
    fileDownloadHandler.WaitUntilDownloadCompleted(200);
}

EDIT: After the comments below, this answer was accepted. So I'm assuming the following code works (which is taken from the link to SourceForge in my last comment, notice the ClickNoWait):

using(IE ie = new IE(someUrlToGoTo))
{
    FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(fullFileName);
    ie.AddDialogHandler(fileDownloadHandler);

    ie.Link("startDownloadLinkId").ClickNoWait();

    fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
    fileDownloadHandler.WaitUntilDownloadCompleted(200);
}

这篇关于在下载IE9与华廷文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆