如何在selenium中指定下载文件名或检索下载的文件?

时间:2012-07-23 20:50:38

标签: c# selenium

我使用selenium for / .NET 4.0和C#/。

我通过输入日期范围并单击导出来下载文件:

这会自动将CSV下载到我的浏览器上设置的默认下载位置:

enter image description here

public static void Downloadreport()
{
    selenium.Open("https://mlis.millenniumlabs.com/Admin/Reports/SpecimenVolume.aspx");

    //selenium.Click("link=Specimen Volume Report - Drugs");
    selenium.WaitForPageToLoad("30000");
    selenium.Click("id=ctl00_cphBody_dtpFrom");
    selenium.Type("id=ctl00_cphBody_dtpFrom", DateTime.Now.ToString("MM/dd/yyyy"));
    selenium.Type("id=ctl00_cphBody_dtpTo", DateTime.Now.ToString("MM/dd/yyyy"));
    selenium.Click("id=ctl00_cphBody_btnExport");
    selenium.SetSpeed("6000");
    Console.WriteLine("Waiting for result complete");
    selenium.IsTextPresent("Specimen Volume Report");
    selenium.IsTextPresent("Display Specimen Detail");

}

我无法控制文件名,我想知道我是否有可能:

  1. 在下载文件之前,明确指定文件名;或
  2. 抓取上次下载文件的文件名?
  3. 文件名类似于:Export23498238974.csv

0 个答案:

没有答案