简体   繁体   English

WatiN从网页下载文件

[英]WatiN downloading a file from webpage

I have the following code which does a couple of webpage redirections and then clicks an tag which has a JavaScript function as the href. 我有以下代码,它执行几个网页重定向,然后单击具有JavaScript函数作为href的标记。 When it is called a file is download. 当它被称为文件下载。 My problem is I want to be able to download the file without being prompted to cancel, save or open. 我的问题是我希望能够下载文件而不会被提示取消,保存或打开。 I am using IE9. 我正在使用IE9。

using (var browser = new IE("http:url.aspx")) {
    browser.TextField(Find.ByName("ctl00$ContentPlaceHolder1$Login1$UserName")).TypeText("cpereyra");
    browser.TextField(Find.ByName("ctl00$ContentPlaceHolder1$Login1$Password")).TypeText("Maxipereyra15");

    browser.Button(Find.ByName("ctl00$ContentPlaceHolder1$Login1$LoginButton")).Click();


    browser.GoTo("http://it-motivity-cmc/Movation/MyPage/MyDashboard.aspx?dynamicdashboardid=ab000000-7dea-11c9-b596-d01e04bebb94");

    while (browser.Eval("document.readyState") != "complete") {
        Thread.Sleep(1000); 
    }

    Div div = browser.Div("ctl00_ContentPlaceHolder1_wrapper_vis_zone1_1");
    div.Link(link => link.Text == "Export to CSV").Click();
}

You have to check inside the js function, and then replicate the call it does to just download the file. 您必须检查js函数内部,然后复制它所做的调用以仅下载文件。 To see the function, just open the js console ( F12 ) type the function name without parentheses, and the function body will appear. 要查看该函数,只需打开js控制台(F12),输入不带括号的函数名称,函数主体就会出现。 You will probably find a clean link inside the function. 您可能会在函数内部找到一个干净的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM