Wait for Download to finish in selenium webdriver JAVA

后端 未结 13 1702
醉话见心
醉话见心 2020-12-01 14:38

Once clicking a download button, files will be downloaded. Before executing next code, it needs to wait until the download completes.

My code looks like this:

<
13条回答
  •  日久生厌
    2020-12-01 15:01

    Some operating systems (e.g. Mac OS X) don't set the filename until the download is complete. So it seems sufficient to use a wait or a while loop to check for the file to exist.

    e.g.

    File file = new File(fullPathToFile);
    while (!file.exists()) {
        Thread.sleep(1000);
    }
    

提交回复
热议问题