Search code examples
c#seleniumdownloadverify

How do I verify if a file is being downloaded in Selenium Webdriver C#


How to verify file being downloaded. I am stuck at how do I retrieve the downloaded file when the "Download" button had been clicked.

''  driver = new ChromeDriver();
        driver.Manage().Window.Maximize();
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
        driver.Navigate().GoToUrl("http://192.162.0.1/testing-admin/Login/Login.aspx");
        driver.FindElement(By.Id("ctl00_MainContent_ucLogin_txtUserID")).SendKeys("Jojo");
        driver.FindElement(By.Id("ctl00_MainContent_ucLogin_txtPassword")).SendKeys("Man15742368");
        driver.FindElement(By.Id("ctl00_MainContent_ucLogin_cmdLogin")).Click();
        driver.Navigate().GoToUrl("http://192.162.0.1/testing-admin/User_Document/User_Document_Download.aspx");
      driver.FindElement(By.XPath("//a[@id='ctl00_MainContent_GV_ctl02_lnkDownloadFile']")).Click(); //download button

Solution

  • var Path = "drive path";
    ChromeOptions co = new ChromeOptions();
    co.AddAdditionalCapability("download.default_directory", Path);
    driver = new ChromeDriver(co);
    

    Then you can you System.IO.DirectoryInfo for retrieving all downloaded file details into Path folder.