Tutorials Hut

  • Selenium WebDriver

       Selenium Introduction
       Benefits of Selenium
       Four components of Selenium
       Difference b/w Selenium IDE, RC & WebDriver
       Selenium WebDriver Architecture
       Background when user execute selenium code
       Download and Install Java
       Download and Install Eclipse
       Download Selenium WebDriver
       Selenium WebDriver Locators
       Selenium - Launch Browser
       Selenium WebDriver Waits
       Selenium- Implicit wait
       Selenium- Explicit wait
       Selenium- Fluent wait
       Selenium- Commonly used commands
       Selenium- findElement & findElements
       Selenium- Selenium-Handling check Box
       Selenium- Handling Radio button
       Selenium- Handling drop down
       Selenium- Take Screenshot
       Selenium- Handle Web Alerts
       Selenium- Multiple Windows Handling
       Selenium- Handle iframes
       Selenium- Upload a file
       Selenium- Download a file
       Selenium- Actions Class Utilities
       Selenium- Mouse Actions
       Selenium- Keyboards Events
       Selenium- Handle mouse hover Actions
       Selenium- Drag and Drop
       Selenium- Scroll a WebPage
       Selenium- Context Click / Right Click
       Selenium- Double Click
       Selenium- Desired Capabilities
       Selenium- Assertions
       Selenium- Exceptions and Exception Handling
       Selenium- Difference b/w driver.close() & driver.quit()
       Selenium- difference b/w driver.get() & driver.navigate()
       Selenium- JavascriptExecutor
       Selenium- Read excel file using Fillo API
       Selenium- Database Testing using Selenium
       Selenium- Read & write excel file using Apache POI
       Selenium- Read and Write csv file in Selenium
       Selenium- Dynamic Web Table Handling
       Selenium- Maven Integration with Selenium
       Selenium- Set up Logging using Log4j
       Selenium-Implement Extent Report



  • How to download files in Selenium using the Firefox browser?

    In this section we will learn about how to download files in Selenium webdriver from the firefox browser.

    let’s say if  we click on any link or  download button in firefox browser then it will display a dialog box window which displays an option to Save or Cancel the file download. 

    whether we download any file using chrome then It will start downloading the file by default once we click on any link or download button.

    Firefox behaviour after clicking on Download- Selenium

    Steps:

    Step 1- Create a firefox Profile.

    Step 2- set Preferences as per requirement.

    Step 3- Open Firefox with firefox profile.

    Let us implement the same through Script.

    Set Firefox’s preferences to save automatically, and not have the downloads window popup. Then you just grab the file, and it’ll download.

    // Create a profile

    FirefoxProfile fp = new FirefoxProfile(); 

    //Set Default Location to store files after downloading.

    fp.setPreference("browser.download.dir","D:\\Downloads"); 

    //Set Preference to not show file download confirmation dialogue using MIME types or different file extension for eg (text/plain ,application/pdf ,text/csv etc)

    fp.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv"); 

    //If it is set as ‘2 ’ save file at the location specified for the most recent download, if value is 1 then save all the file on download folder  and if value is 0 then save all files on the desktop

    fp.setPreference("browser.download.folderList",2); 
    fp.setPreference("browser.download.manager.showWhenStarting",false);

    // Open browser with profile

    WebDriver driver = new FirefoxDriver(fxProfile); 
    driver.navigate().to("http://the-internet.herokuapp.com/download/hello_world.txt");

    We can also set firefox profile settings manually as well instead of setting through code 

    1) Open Firefox and in url box type about:config and press enter

    2) In Search bar type neverask and enter and then you will find below setting

    Firefox File Download About Config- Selenium

    3) We have to set the value of file type for parameter browser.helperApps.neverAsk.saveToDisk  so that the FireFox browser will not ask for permission to download files.

    Below is the scenario which we will automate to show how the handle downloads using firefox 

      1. Open Firefox browser
      2. Navigate to ‘http://the-internet.herokuapp.com/download
      3. click on link ‘hello_world.txt
      4. close the browser

    code Implementation

    package com.test;
    
    import java.util.concurrent.TimeUnit;
    
    import org.openqa.selenium.*;
    
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    import org.openqa.selenium.firefox.FirefoxProfile;
    
    public class DownloadFile {
    
    public static WebDriver driver;
    
    public static void main(String[] args) {
    
     //Create a FireFox Profile object
    
    FirefoxProfile fp = new FirefoxProfile();
    
    //Set Default Location to store files after downloading.
    
    fp.setPreference("browser.download.dir", "D:\\Downloads");
    
    fp.setPreference("browser.download.folderList", 2);
    
    //Set Preference to not show file download confirmation dialogue using MIME types Of different file extension types.
    
    fp.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv"); 
    
    fp.setPreference( "browser.download.manager.showWhenStarting", false );
    
    //Pass firefox profile parameter In webdriver to use preferences to download file.
    
    WebDriver driver = new FirefoxDriver(fp);
    
    // Open below URL
    
    driver.get("http://the-internet.herokuapp.com/download/");
    
    // Click to download 
    
    driver.findElement(By.linkText("hello_world.txt")).click();
    
    Thread.sleep(4000);
    
    driver.close();
    
    }
    
    }
    
    



  • Selenium WebDriver Tutorials

       Selenium Introduction
       Benefits of Selenium
       Four components of Selenium
       Difference b/w Selenium IDE, RC & WebDriver
       Selenium WebDriver Architecture
       Background when user execute selenium code
       Download and Install Java
       Download and Install Eclipse
       Download Selenium WebDriver
       Selenium WebDriver Locators
       Selenium - Launch Browser
       Selenium WebDriver Waits
       Selenium- Implicit wait
       Selenium- Explicit wait
       Selenium- Fluent wait
       Selenium- Commonly used commands
       Selenium- findElement & findElements
       Selenium- Selenium-Handling check Box
       Selenium- Handling Radio button
       Selenium- Handling drop down
       Selenium- Take Screenshot
       Selenium- Handle Web Alerts
       Selenium- Multiple Windows Handling
       Selenium- Handle iframes
       Selenium- Upload a file
       Selenium- Download a file
       Selenium- Actions Class Utilities
       Selenium- Mouse Actions
       Selenium- Keyboards Events
       Selenium- Handle mouse hover Actions
       Selenium- Drag and Drop
       Selenium- Scroll a WebPage
       Selenium- Context Click / Right Click
       Selenium- Double Click
       Selenium- Desired Capabilities
       Selenium- Assertions
       Selenium- Exceptions and Exception Handling
       Selenium- Difference b/w driver.close() & driver.quit()
       Selenium- difference b/w driver.get() & driver.navigate()
       Selenium- JavascriptExecutor
       Selenium- Read excel file using Fillo API
       Selenium- Database Testing using Selenium
       Selenium- Read & write excel file using Apache POI
       Selenium- Read and Write csv file in Selenium
       Selenium- Dynamic Web Table Handling
       Selenium- Maven Integration with Selenium
       Selenium- Set up Logging using Log4j
       Selenium-Implement Extent Report

















  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    Scroll to Top