0
我看過幾個問題,詢問是否可以檢查特定下載是否完成,或者是否已成功完成特定下載。 (答案似乎爲否)檢查Seleniums chrome瀏覽器是否正在下載
我想知道的是:是否有可能看到硒是否正在下載任何文件?即無論它是一個文件還是20個都沒關係。像一個小布爾檢查會很理想。
我看過幾個問題,詢問是否可以檢查特定下載是否完成,或者是否已成功完成特定下載。 (答案似乎爲否)檢查Seleniums chrome瀏覽器是否正在下載
我想知道的是:是否有可能看到硒是否正在下載任何文件?即無論它是一個文件還是20個都沒關係。像一個小布爾檢查會很理想。
當Chrome下載文件時,您可以檢查Chrome下載的臨時文件(* .crdownload
)的下載文件夾。下載完成後,文件被實際的文件名/類型「替換」。
/// <summary>
/// Looks for a file with the given extension (Example: "*.crdownload") in the current user's "Download" folder.
/// </summary>
public static string LocateDownloadedFile(string fileExtension)
{
// Get the default downloads folder for the current user
string downloadFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads";
DirectoryInfo di = new DirectoryInfo(downloadFolderPath);
FileInfo[] filesFound = di.GetFiles(fileExtension);
if (filesFound.Length == 0)
{
// do stuff
}
else
{
// do other stuff
}
}