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

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


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.


You need to use ROBOT class for firing an ENTER Action event. In java if you want to fire any event you have to use Robot class for typing using programatically or firing events like ENTER and ESCAPE.

// Create object of Robot classRobot object=new Robot();// Press Enterobject.keyPress(KeyEvent.VK_ENTER);// Release Enterobject.keyRelease(KeyEvent.VK_ENTER);

and for information regarding this you can use this link


Got it working using the following setup:

FirefoxOptions options = new FirefoxOptions();FirefoxProfile profile = new FirefoxProfile();profile.setPreference("browser.download.folderList", 2);profile.setPreference("browser.download.dir", "C:\\Windows\\temp");profile.setPreference("browser.download.useDownloadDir", true);profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");options.setProfile(profile);driver = new FirefoxDriver(options);

More info about Preference settings can be found here: http://toolsqa.com/selenium-webdriver/how-to-download-files-using-selenium/.