How do i change the location where my file gets downloaded in Selenium Webdriver and firefox driver?

0 votes

I'm trying to save an image using 'save as' option to a particular folder. I found a way to right click on that image, but the problem is, after getting the popup to save the file, i'm not able to set the path where to sava it to. Plz help.

The code for Firefox is:-

public class practice {

 public void pic() throws AWTException{
     WebDriver driver;

     //Proxy Setting     
        FirefoxProfile profile = new FirefoxProfile();
        profile.setAssumeUntrustedCertificateIssuer(false);
        profile.setEnableNativeEvents(false);
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", "localHost");
        profile.setPreference("newtwork.proxy.http_port",3128);

        //Download setting
        profile.setPreference("browser.download.folderlist", 2);
        profile.setPreference("browser.helperapps.neverAsk.saveToDisk","jpeg");
        profile.setPreference("browser.download.dir", "C:\\Users\\Admin\\Desktop\\ScreenShot\\pic.jpeg");
        driver = new FirefoxDriver(profile);

        driver.navigate().to("http://stackoverflow.com/users/2675355/shantanu");
        driver.findElement(By.xpath("//*[@id='large-user-info']/div[1]/div[1]/a/div/img"));
        Actions action = new Actions(driver);
        action.moveToElement(driver.findElement(By.xpath("//*[@id='large-user-info']/div[1]/div[1]/a/div/img"))).perform();
        action.contextClick().perform();
        Robot robo = new Robot();
        robo.keyPress(KeyEvent.VK_V);
        robo.keyRelease(KeyEvent.VK_V);
    // Here i am getting the os window but don't know how to send the desired location
    }//method   
}//class
Apr 12, 2018 in Selenium by kappa3010
• 2,090 points
3,438 views

1 answer to this question.

0 votes

There are a couple of errors there. First set your preferences like this without the image name and format:

profile.setPreference("browser.download.dir", "C:\\Users\\Admin\\Desktop\\ScreenShot\\");

Then if at all your using: browser.download.folderlist, then its wrong usgae. Should be like this (L caps in folderList):
browser.download.folderList

After that,  use then Robot class for desired operations.

answered Apr 12, 2018 by nsv999
• 5,520 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How do I resolve the ElementNotInteractableException in Selenium WebDriver?

Hi Abish, ElementNotInteractableException occurs when an element is ...READ MORE

answered Aug 21, 2019 in Selenium by Abha
• 27,930 points
23,414 views
+1 vote
0 answers

How do I make selenium check gmails quota storage and then execute another task in a new tab depending on the value?

So on the bottom of gmail, there ...READ MORE

4 days ago in Selenium by anonymous
• 130 points
52 views
0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,340 points
1,221 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
3,749 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,730 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,725 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,067 views
+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,520 points
16,988 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,520 points
10,467 views