Unable to Export the partic file andsave to desired location | Selenium Forum
M
Posted on 22/08/2015
Hi All,

I am trying to export the file and save the file to the desired location but I am unable to click on "OK" button and save the file to desired location

Type of file is .csv. I tried firefox profiler but it is not working. Please some one help me in resolving this issue.

Below is the entire code for the same

public class NewDownload {

public static void main(String[] args) throws InterruptedException {


FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);

profile.setPreference("browser.download.dir","E:\\Previous PC\\Selenium\\NewFinal\\AUDI\\src\\com\\audi\\xls\\ExportLocation");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword,application/x-rar-compressed,application/octet-stream,application/vnd.ms-excel,application/csv,text/csv");

WebDriver driver = new FirefoxDriver(profile);
driver.get("http://www.audiresearch.com/login?returnUrl=http%3a%2f%2faudiresearch.com%2f");
driver.findElement(By.xpath("//*[@id='EmailAddress']")).sendKeys("peter@qaiconsulting.com.au");
driver.findElement(By.xpath("//*[@id='Password']")).sendKeys("hurr1cane");
driver.findElement(By.xpath("//button[@type='submit']")).click();
driver.findElement(By.xpath("//*[@id='page-top']/div[2]/div/div/div/div/div/div[3]/div[1]/div/a")).click();
Thread.sleep(15000L);

driver.findElement(By.xpath("//*[@id='kpiTab']")).click();
Thread.sleep(15000L);

driver.findElement(By.xpath("//i[@class='fa fa-download']")).click();
Thread.sleep(9000L);







}

M
Replied on 22/08/2015

I am working on this


M
Replied on 23/08/2015

Ok Ashish

Please try to give me solution as soon as possible


M
Replied on 26/08/2015

Hi Ashish,

I tried your solution and it didn't worked. Please give me the solution for my code


M
Replied on 28/08/2015

Hi

Please give me the soultion


M
Replied on 31/08/2015

Use the below code to save the file after you click on export button.


Robot r = new Robot();
r.keyPress(KeyEvent.VK_DOWN);
r.keyRelease(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_TAB);
r.keyRelease(KeyEvent.VK_TAB);
r.keyPress(KeyEvent.VK_TAB);
r.keyRelease(KeyEvent.VK_TAB);
r.keyPress(KeyEvent.VK_TAB);
r.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(2000);
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);

Let me know if you face any issue.

Thanks,
Elora
http://eloraparija.com


M
Replied on 31/08/2015

use import java.awt.AWTException;


M
Replied on 04/09/2015

Hi Ashish,

I just don't want to just click on "OK" but I want to save it to the desired loacation

How can I do that ?


M
Replied on 04/09/2015

your code is fine cannot find any mistakes but its not working I don't know why.

give me some time.


M
Replied on 19/09/2015

Any solution found ?


M
Replied on 19/09/2015

I still can't find it. but there are few more things I could try. until then use robot class.


M
Replied on 21/09/2015

problems are with properties there is no property called

"browser.download.dir"

alternatively you can set configuration inside "about:config" and then call the same profile from selenium.

Responsive image

M
Replied on 23/09/2015

Hi Ashish/Team,

Even though 'browser.download.dir' firefox config is created manually and value is being updated by code,It is not working.
Also basic download code which was used in Module 16 to demonstrate download file in selenium with different MIME type is not working.
I am facing the same issue there as well and download window was not suppressed.
Could you please do the needful at the earliest ?

P.S. : I haven't strated the new thread as problem is same.

My FF version : 34.0
Selenium Webdriver : 2.45

Code :
public class Downloading_File {

/**
* @param args
*/
public static void main(String[] args) {
FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir","D:\\test");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword,application/x-rar-compressed,application/octet-stream,application/csv,text/csv");

WebDriver driver = new FirefoxDriver(profile);
driver.get("http://qtpselenium.com/test/testdownload.php");
driver.findElement(By.xpath("html/body/a[1]")).click();
driver.findElement(By.xpath("html/body/a[2]")).click();
driver.findElement(By.xpath("html/body/a[3]")).click();

}

}


M
Replied on 23/09/2015

create "Profile1" firefox profile and open "about:config"
search for value "browser.helperApps.neverAsk.saveToDisk" and manipulate it.
and by selenium call that "Profile1".
try this.


M
Replied on 24/09/2015

I did the same
1.) Manually created the profile - profile1
2.) Manually updated the 'browser.helperApps.neverAsk.saveToDisk' configuration for different MIME type.
3.) Accessed the same profile in code .

But No Luck. Please suggest.


M
Replied on 24/09/2015

can you wait till monday 28th.


M
Replied on 25/09/2015

Sure!! Thanks for acknowledging it Responsive image


M
Replied on 25/09/2015

Hi


Thanks for the acknowledgement Responsive image
Please try to give solution which will work for all the applications


M
Replied on 11/10/2015

Please provide me with the solution


M
Replied on 12/10/2015

working on it. don't worry. will provide you a solution when we have it.


M
Replied on 12/10/2015

Ok..Thank you


M
Replied on 12/10/2015

hey we are remaking the modules and it will be among newly uploaded modules.


M
Replied on 13/10/2015

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", "F:\\temp");
//profile.setPreference("browser.helperApps.neverAsk.openFile",
//"text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
WebDriver driver = new FirefoxDriver(profile);