1.webdriver download of the paging file
we generally operate the browser download will let us choose the downloaded directory and then after a series of actions before the file download operation, but with Webdriver can not operate in this way. After querying the data found the following implementation methods. First, you need to set the browser's configuration file when initializing the browser object. To configure the Browser.download.folderList setting to 2, the default to 0 means that the default now path, set to 2 o'clock is saved to the specified directory. Browser.download.manager.showWhenStarting
This is set to show whether the start box is used, we set the default to False;browser.download.dir
This is where you set up the save file download, and finally the heaviest attribute:
Browser.helperApps.neverAsk.saveToDisk, This is the type of setup file download.
If this configuration does not match the type of download, there will be a problem with the download.
The concrete examples are as follows:
Firefoxprofile = new firefoxprofile ();
Firefoxprofile.setpreference ("Browser.download.folderList", 2);
Firefoxprofile.setpreference ("Browser.download.manager.showWhenStarting",false);
Firefoxprofile.setpreference ("Browser.download.dir", "c:\\ automation ");
Firefoxprofile.setpreference ("Browser.helperApps.neverAsk.saveToDisk", "Application/octet-stream," + "application /vnd.ms-excel, Text/csv, Application/zip, Application/exe ");
Driver = new firefoxdriver (firefoxprofile);
2.webdriver Implement File Upload
a plugin that typically uploads files on a page pops up a selection file location, which is a challenge for our automated testing. There are generally two workarounds (1) Use the AutoIt tool to mimic the mouse action click on the page pop-up to select the file location. One drawback of this method is that it is extremely unstable and related to screen resolution, so do not narrate (2) through the page element to find the plug-in location, the input in the label pair to enter the location of the file to achieve the effect of uploading files. Let's take a closer look at my personal insights on this.
First we need to navigate the page to the corresponding upload file button,
after you find this element, use the SendKeys () method to enter the absolute path name of the file you want to upload, and you have achieved the purpose of selecting the file.
Selenium Java file upload, download