Selenium Java file upload, download

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.