Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download .docx file using Selenium webdriver in Java?

Can anyone let me know how to download a word file using selenium(java)? My below code is not working.

FirefoxProfile prof = new FirefoxProfile();
prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/word");

When I click on 'download link or icon' in the page, it prompts a popup to save the download file (see image below) and I need to click on OK button in the popup.

Please let me know how to do this using Firefox.

Save Popup

like image 793
Deepak gupta Avatar asked Apr 21 '15 11:04

Deepak gupta


People also ask

How do you download any file and save it to the desired location using Selenium Webdriver?

New Selenium IDE We can download any file and save it to the desired location with Selenium. This can be done by creating an instance of the FirefoxOptions class. Then with the help of the addPreference method, we have to set the browser preferences.

Can we upload/download file using Selenium?

The most basic way of uploading files in Selenium is using the sendKeys method. It is an inbuilt feature for file upload in Selenium. The syntax is as below: WebElement upload_file = driver.

How does Python handle print preview in Selenium?

Alert printDialog = driver. switchTo(). alert(); printDialog. dismiss();


1 Answers

Try this

import java.awt.Robot;

And use

Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);

This will press Enter Programatically.

like image 97
Vaibhav Avatar answered Oct 11 '22 10:10

Vaibhav