重复下载不可靠吗?
WatiN 似乎不能一致地处理重复的下载对话框:
foreach (string file in lstFiles)
{
// continue if no download link
if (!ie.Element([search criteria]).Exists) continue;
var btnDownload = ie.Element([search criteria]);
string fullFilename = workingDir + "\\" + file;
FileDownloadHandler download = new FileDownloadHandler(fullFilename);
using (new UseDialogOnce(ie.DialogWatcher, download))
{
btnDownload.ClickNoWait();
download.WaitUntilFileDownloadDialogIsHandled(30);
download.WaitUntilDownloadCompleted(150);
ie.RemoveDialogHandler(download);
}
}
基本上,我循环浏览我期望可用的文件名列表,然后单击下载按钮。这通常有效,但是经过多次下载(情况各不相同,有时所有可用的下载,有时什么都没有),它会在等待处理对话框时挂起。该按钮被正确识别,下载对话框出现,只是没有被检测和处理。它不是特定于站点的,因为其他站点上的类似方法也取得了不同程度的成功。有人以前遇到过这个问题并知道解决方法吗?
编辑:重复下载在 Server 2008 中不起作用。在 Win7 中,这种情况在一次或多次成功重复下载后随机发生。
WatiN seems to not handle repeated download dialogs consistently:
foreach (string file in lstFiles)
{
// continue if no download link
if (!ie.Element([search criteria]).Exists) continue;
var btnDownload = ie.Element([search criteria]);
string fullFilename = workingDir + "\\" + file;
FileDownloadHandler download = new FileDownloadHandler(fullFilename);
using (new UseDialogOnce(ie.DialogWatcher, download))
{
btnDownload.ClickNoWait();
download.WaitUntilFileDownloadDialogIsHandled(30);
download.WaitUntilDownloadCompleted(150);
ie.RemoveDialogHandler(download);
}
}
Basically, I loop through a list of filenames that I expect to be available and click the download button. This usually works, but after so many downloads (it varies, sometimes everything that's available downloads, sometimes nothing) it will hang while waiting to handle the dialog. The button's identified correctly, the download dialog appears, it just isn't detected and handled. It isn't site-specific as similar methods on other sites are also met with variable success. Anyone encounter this before and know of a resolution?
edit: Repeated downloads do not work whatsoever in Server 2008. In Win7, this happens randomly after one or more successful repeated downloads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
出现此问题的原因是 IE 文件下载对话框由 2 个窗口组成。 WatiN DialogWatcher 获取所有系统窗口并尝试在 foreach 循环中处理它们。处理第一个正确的对话框窗口后,DialogWatcher 获取下一个具有相同属性并且是有效下载对话框的窗口。 DialogWatcher 开始等待,直到该窗口可见,但在处理前一个窗口后立即关闭。
我的解决方案是在处理任何对话框后从 foreach 循环返回:
The problem appears because IE File Download Dialog consist of 2 windows. WatiN DialogWatcher gets all the system windows and tries to handle them in foreach loop. After handling first correct dialog window DialogWatcher gets the next window wich has the same properties and is a valid Download Dialog. DialogWatcher starts waiting until this window is visible but it closes immediately after previos window is handled.
My solution is to return from foreach loop after any dialog is handled:
我的团队在使用 WatiN 自动化 IE8 时也遇到了这个问题。问题似乎与 IE 相关,可能需要进行一些耗时的清理工作。我们最终使用的解决方法是在外部循环中调用 IE 的 new 实例,每次迭代都会处理它,然后等待 5 秒以解决后台发生的任何问题。这是一次黑客攻击,但完成了工作。
My team ran into this as well while automating IE8 with WatiN. The problem seems to be with IE, possibly doing some time consuming house-cleaning. The work-around we ultimately used was to invoke a new instance of IE within the outer loop, disposing of it each iteration and then waiting for 5 seconds for whatever was going on in the background to resolve. It was a hack but got the job done.