java + selenium + new-- unmanned automatic download file - based firefox browser

My own python Reference: https://www.cnblogs.com/xiaobaibailongma/p/12078159.html

 

FirefoxProfile fp = new FirefoxProfile();

fp.setPreference ( "browser.download.manager.showWhenStarting", False) // set to true, when you start downloading, the browser displays the File Download window, false is not displayed

fp.setPreference ( "browser.download.folderList", 2) // Set the default Firefox download files folder. 0 is a desktop; 1 is "My Downloads"; 2 custom.

// set path custom path, defined by: fp.setPreference ( "\\ Users \\ del \\ Desktop \\ 1 C" "browser.download.dir",)

fp.setPreference ( "browser.helperApps.neverAsk.saveToDisk", "application / zip") // Do not ask download path; behind the parameter values ​​that you want to download the file type of the page.

fp.setPreference ( "browser.helperApps.neverAsk.saveToDisk", "application / octet-stream") // Do not ask download path; behind parameter value of the file type to download pages. Exe file here

 

===================================================================================================================================

 

package rjcs;



import java.util. * ;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class xinkaishi 
{

    
    public static void main(String[] args)
    
    {
         System.setProperty ( "webdriver.firefox.bin", "C: \\ Program Files (the x86) \\ \\ firefox.exe the Mozilla Firefox");     // set the installation path Firefox, preventing system can not find 
            
         FirefoxDriver Driver = new new FirefoxDriver ();         // initialize FireFox browser instance, and open the browser
         
        try
        {
             . driver.manage () window () the Maximize ();.          // maximize the window 
             
             Thread.sleep ( 5000 );    
               
             
             FirefoxProfile fp = new FirefoxProfile();

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

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

             fp.setPreference("browser.download.dir","C:\\Users\\del\\Desktop\\1");

             fp.setPreference("browser.helperApps.neverAsk.saveToDisk","application/zip");
             
             
             
             Thread.sleep(5000);
             
             driver.navigate().to("https://www.python.org/downloads/release/python-381/"); 
             
             
             Thread.sleep(5000);
             
             driver.findElementByLinkText("Windows x86-64 executable installer").click();

             
             
             Thread.sleep(80000);
             
             
        }catch (Exception e) 
        {
            e.printStackTrace ();
        }finally 
        {
            driver.quit();
        
         }
    }
    
    
    
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/xiaobaibailongma/p/12293621.html