Wait for File Download using FluentWait in Selenium

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 พ.ย. 2023
  • In this video, I have explained how to Wait for File Download using FluentWait in Selenium
    Schedule a meeting in case of any queries/guidance/counselling:
    calendly.com/naveenautomation...
    ~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
    th-cam.com/users/Naveen%20Au...
    Follow me on my Facebook Page:
    / naveenqtpexpert
    Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
    t.me/joinchat/9FrG-KzGlvxjNmQ1
    Naveen AutomationLabs Paid Courses:
    GIT Hub Course:
    naveenautomationlabs.com/gitc...
    Java & Selenium:
    naveenautomationlabs.com/sele...
    Java & API +POSTMAN + RestAssured + HttpClient:
    naveenautomationlabs.com/manu...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 37

  • @naveenautomationlabs
    @naveenautomationlabs  8 หลายเดือนก่อน +3

    public class FileDownload {
    public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.get("get.jenkins.io/windows-stable/2.426.1/jenkins.msi");
    String downloadPath = "/Users/naveenautomationlabs/Downloads";
    String fileName = "jenkins.msi";
    File file = new File(downloadPath, fileName);
    FluentWait wait = new FluentWait(file)
    .withTimeout(Duration.ofMinutes(5))
    .pollingEvery(Duration.ofSeconds(2))
    .ignoring(Exception.class).withMessage("file is not downloaded");
    try {
    boolean isDownloaded = wait.until(f -> f.exists() && f.canRead());
    if (isDownloaded) {
    System.out.println("file is completely 100% downloaded");
    }
    } catch (TimeoutException e) {
    System.out.println("file is not completely downloaded");
    }
    }
    }

  • @Little-Impact
    @Little-Impact 8 หลายเดือนก่อน +1

    You are a Champion. Thanks a lot bro for sharing your knowledge.

  • @siddabattuniharinadh1371
    @siddabattuniharinadh1371 8 หลายเดือนก่อน

    Clean & Clear cut explanation.
    Thank you.

  • @laxmikambar7610
    @laxmikambar7610 8 หลายเดือนก่อน +1

    Thanks Naveen for the information

  • @arunkumarpandey4989
    @arunkumarpandey4989 8 หลายเดือนก่อน

    Thanku so much Naveen, i just implemented this logic in my code.

  • @nityaranjan6714
    @nityaranjan6714 8 หลายเดือนก่อน +1

    Very helpful..

  • @swapnilkhute
    @swapnilkhute 8 หลายเดือนก่อน

    Always something unique 👍🏻

  • @bihari1422
    @bihari1422 8 หลายเดือนก่อน +1

    I have faced this scenario earlier and used the count method to identify if the file is downloaded or not (It was working fine). Going forward I will use this fluent wait concept.(Was not aware that it can accept any type as parameter).
    Thank You !!

  • @vinayakbhandurge6290
    @vinayakbhandurge6290 8 หลายเดือนก่อน +1

    Bhari 👍

  • @SameerKumar-yu1xi
    @SameerKumar-yu1xi 8 หลายเดือนก่อน +1

    Genius 😎

  • @shoaibsheikh863
    @shoaibsheikh863 24 วันที่ผ่านมา

    Hats off

  • @karthickrajpattabi
    @karthickrajpattabi 8 หลายเดือนก่อน +1

    G.O.A.T

  • @dheerajsingh6568
    @dheerajsingh6568 2 หลายเดือนก่อน

    Awesome Naveen, I have some doubt. How to handle the delete from download section and then verify because we can't delete it again and again manually as it will cost time ?

  • @user-cx2hw4pe9z
    @user-cx2hw4pe9z 8 หลายเดือนก่อน

    Thank you @Naveen! How can a page refreshed mechanism be added to the code? I need to click on a download link which may not be present when i land on the page so i need to refresh the page like 3x before quiting if element is not clickable.

  • @venkychowdary5432
    @venkychowdary5432 8 หลายเดือนก่อน +2

    Hi Naveen thanks for this video. May I know how f becomes file object? With our creation File object..

    • @naveenautomationlabs
      @naveenautomationlabs  8 หลายเดือนก่อน

      because of generics type is File in FluentWait

  • @zaigamalimerchant4733
    @zaigamalimerchant4733 8 หลายเดือนก่อน

    Hi Naveen, Will this same scenario work for the headless Chrome browser?

  • @yuvraj4870
    @yuvraj4870 6 หลายเดือนก่อน

    Thanks Naveen, can you also please explain how to do this without lambda expressions ?

  • @lokapavanikoduru9966
    @lokapavanikoduru9966 8 หลายเดือนก่อน

    To answwer the interview question? which version of webdriver you are using in your project?

  • @harshakalal529
    @harshakalal529 2 หลายเดือนก่อน

    Did you delete your selenium playlist videos -the basics one?

  • @satheeskumar9343
    @satheeskumar9343 8 หลายเดือนก่อน +1

    Hi Naveen, What will happen if we ignore the timeout exception?

    • @naveenautomationlabs
      @naveenautomationlabs  8 หลายเดือนก่อน +1

      It will anyhow throw the timeout exception after the total timeout.

  • @balakumaran6227
    @balakumaran6227 8 หลายเดือนก่อน +1

    when we try to download any file in incognito mode.. it asking for saveas popup... how to fix that .. even we set the chrome options of downloads path it is not working.. can you help me on this.. i tried in both selenium and playwright it give same result.. is this issue with recent update of chrome driver. am using 119 chrome

    • @naveenautomationlabs
      @naveenautomationlabs  8 หลายเดือนก่อน

      ok, will check this.

    • @Little-Impact
      @Little-Impact 8 หลายเดือนก่อน

      Add the following lines of code:
      Map prefs = new HashMap();
      prefs.put("safebrowsing.enabled", true);
      ChromeOptions options = new ChromeOptions().setExperimentalOption("prefs", prefs);

  • @ravicommando1
    @ravicommando1 8 หลายเดือนก่อน +2

    Hi Naveen, can you please share the code here pls...

  • @jayt-ph1xd
    @jayt-ph1xd 8 หลายเดือนก่อน +1

    What to do if the filename is different every time?

    • @naveenautomationlabs
      @naveenautomationlabs  8 หลายเดือนก่อน +1

      you can create a generic function and parameterize it.

    • @jayt-ph1xd
      @jayt-ph1xd 8 หลายเดือนก่อน

      @@naveenautomationlabs the file download is different everytime and we don't know what the name will be just a pattern which is followed. I was looking into the directorystream class to do this but haven't tried it yet.

  • @sriramkukkadapu1049
    @sriramkukkadapu1049 8 หลายเดือนก่อน

    Interviewe next question:
    1.Do the same without Fluent wait ?
    2. If the file is already downloaded, your script should be intelligent enough to delete the old file and re-download the new file.
    3. During the file download if suddenly download fails how your script will handle that.

    • @bihari1422
      @bihari1422 8 หลายเดือนก่อน

      1. Use count method in the folder to check the downloaded file is present
      2. If not required, its always a good practice to clean the download directory before launching the browser.
      3. Here count method can come handy and will be able to identify the file was not downloaded and we can recall the method again upon failure

    • @ahamedabdulrahman
      @ahamedabdulrahman 8 หลายเดือนก่อน

      Count method alone cant be used as we would have jenkins.msi.crdownload file presence while downloading. You would need to wait for this particular file’s absence.
      This is for Chrome, it would change for other browsers I suppose.

    • @ahamedabdulrahman
      @ahamedabdulrahman 8 หลายเดือนก่อน

      4. What will you do if the file name is not known.

    • @bihari1422
      @bihari1422 7 หลายเดือนก่อน

      @@ahamedabdulrahman downloading does not require file name to be known

  • @MrMohit09
    @MrMohit09 8 หลายเดือนก่อน

    public static void waitForFileDownload(WebDriver driver, String filePath) {
    FluentWait wait = new FluentWait(driver)
    .withTimeout(Duration.ofSeconds(60)) // Maximum wait time for the file download (adjust as needed)
    .pollingEvery(Duration.ofSeconds(2)) // Polling interval
    .ignoring(NoSuchElementException.class); // Ignore NoSuchElement exceptions
    // Custom expected condition to check if the file exists at the specified path
    wait.until((WebDriver webDriver) -> {
    File file = new File(filePath);
    return file.exists() && file.isFile();
    });
    }