使用 Watin 下载文件
如何使用 watin 下载文件?我搜索了很多并尝试过,但我无法得到它。 我只想单击有下载的链接并保存它。我使用了我找到的例子,但没有成功。问题是我使用“WaitUntilFileDownloadDialogIsHandled(15)”,但 15 秒过去了并抛出异常: WatiN.Core.Exceptions.WatiNException :15 秒后未显示对话框。
这是代码:
FileDownloadHandler download = new FileDownloadHandler("C:/Development/Test/Downloads/" + "excel" + ".xls");
using (new UseDialogOnce(browser.DialogWatcher, download))
{
browser.Button(Find.ById("id_of_the_button")).ClickNoWait();
download.WaitUntilFileDownloadDialogIsHandled(15);
download.WaitUntilDownloadCompleted(150);
browser.RemoveDialogHandler(download);
}
请帮忙!
How can i download a file with watin? I searched a lot and tryied but i cant get it.
I only want to click on a link that have a download and save it. I used examples that i found but without success. The problem is that i use "WaitUntilFileDownloadDialogIsHandled(15)" but the 15 seconds pass and throw and exception: WatiN.Core.Exceptions.WatiNException : Has not shown dialog after 15 seconds.
This is the code:
FileDownloadHandler download = new FileDownloadHandler("C:/Development/Test/Downloads/" + "excel" + ".xls");
using (new UseDialogOnce(browser.DialogWatcher, download))
{
browser.Button(Find.ById("id_of_the_button")).ClickNoWait();
download.WaitUntilFileDownloadDialogIsHandled(15);
download.WaitUntilDownloadCompleted(150);
browser.RemoveDialogHandler(download);
}
Please, help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用了以下代码片段,效果非常好。
我使用的代码片段中唯一的区别是我使用了带有转义字符的反斜杠,并且我在没有使用块的情况下添加和删除了 DialogHandler。
~阿希什·纳尔曼
I had used the following code snippet that worked absolutely fine
The only difference in the code snippet that I used was that I used a backslash with the escape character and that I added and removed the DialogHandler without an using block.
~Ashish Narmen
使用 WAIN 下载文档
To Download Documents using WATIN
我确实发现了一个困扰我的问题,
请注意包含“CloseUnhandledDialogs = false”行。我的保存对话框弹出窗口立即消失,我花了很长时间才意识到发生了什么。
I did discover one issue that plagued me
Note the inclusion of the "CloseUnhandledDialogs = false" line. My save dialog popup was disappearing immediately and it took me forever to realize what was going on.