I used this code for download file , but its not working
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir","D:\\WebDriverDownloads");
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
profile.setPreference( "browser.download.manager.showWhenStarting",false );
profile.setPreference( "pdfjs.disabled",true );
FirefoxDriver driver = new FirefoxDriver(profile); //Shows error on this line
driver.get("http://toolsqa.com/automation-practice-form/");
driver.findElement(By.linkText("Test File to Download")).click();
Thread.sleep(5000);
It gives me error
And when I remove
'Profile'
form this FirefoxDriver driver = new FirefoxDriver(profile);
then code run successfully but download files window is not closing and file also not downloading.
Instead of this I use Robot
Robot object=new Robot();
object.keyPress(KeyEvent.VK_DOWN);
object.keyRelease(KeyEvent.VK_DOWN);
object.keyPress(KeyEvent.VK_ENTER);
object.keyRelease(KeyEvent.VK_ENTER);
and its working fine.But Why my above code is not working?