I need to automate the following test senario where

when I click on a button, a file will be downloaded

There will be no message box and no text message. How should I implement this scenario using selenium script?


2 Answers 2


You can check the filesystem for the downloaded file:

private boolean isFileDownloaded(String downloadPath, String fileName){
    boolean flag = false;
    File dir = new File(downloadPath);
    File[] dirContent = dir.listFiles();

    assert dirContent != null;
    for(File file : dirContent){
        if (file.getName().equals(fileName)) { return flag = true; }
    return flag;

NOTE: This is a Java implementation, you can use the same idea in C#.


The process of downloading a file is a browser activity regarding HTTP requests and the file system.

So Selenium is not the appropriated tool, because its concern is limited to the DOM.

Selenium would fit the point of clicking the button.

If your goal is to check the browser itself, you should use unit and integration checks.

If your goal is to check the content of the file in certain URL, you can use HTTP clients such as C#'s built-in HTTP client.

Not the answer you're looking for? Browse other questions tagged or ask your own question.