Nic*_*lam 7 c# watin internet-explorer-9
我在自动化从网站下载文件的过程中遇到了问题.该网站有一个Java按钮,单击该按钮会触发下载Excel文件.我正在使用最新版本的Watin(v2.1).
我设法让Watin登录网站,导航到相应的页面,更改页面上的参数,然后单击按钮开始下载.
但是,当下载完成后,IE9下载框出现,没有任何反应,直到Watin超时.
我很感激任何建议,因为我看不到任何下载文件或保存文件的方法.即使它将'Alt + S'传递给页面,也可以保存它.我试过通过WatinTestRecorder运行它,并没有提示保存.
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!
}
Run Code Online (Sandbox Code Playgroud)
从版本1.1.0.4000开始应该支持此功能.该版本的发行说明不再在线(http://watin.org/documentation/),但我在Googles缓存中找到了它(http://svn6.assembla.com/svn/ci-samples/dotnet/ watir/website/releasenotes-1-1-0-4000.html)
它应该是这样的:
using(IE ie = new IE(someUrlToGoTo))
{
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(fullFileName);
ie.AddDialogHandler(fileDownloadHandler);
ie.Link("startDownloadLinkId").Click();
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
}
Run Code Online (Sandbox Code Playgroud)
编辑:在下面的评论之后,这个答案被接受了.所以我假设以下代码有效(这是我在上一条评论中从SourceForge的链接中获取的,请注意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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8656 次 |
| 最近记录: |