Webdriver Firefoxdriver Selenium download file

Asked

Viewed 400 times

0

I am automating the download of a file .xlsx of a website with Selenium with the FirefoxDriver but I can’t interact in the download pop-up of the site!

inserir a descrição da imagem aqui

There’s how I interact with the pop-up by checking Save file and upload to a folder?

I’m using the following code to interfere with the pop-up:

IWebDriver driver = new FirefoxDriver();
            driver.Url = "";

            driver.Manage().Window.Maximize();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
           driver.FindElement(By.XPath("//button[@class='jss174']")).Click();

            Thread.Sleep(6000);

            driver.FindElement(By.XPath("//input[@class='jss314']")).Click();

            Thread.Sleep(6000);

            driver.FindElement(By.XPath("//img[@src='a95fbd8f692090fb308a787688c0373f.png']")).Click();

            FirefoxProfile profile = new FirefoxProfile();

            profile.AcceptUntrustedCertificates = true;           

            profile.SetPreference("browser.download.folderList", 2);

            profile.SetPreference("browser.download.dir", "c:\\mydownloads");

            //profile.SetPreference("network.http.phishy-userpass-length", 255);
            profile.SetPreference("browser.download.manager.showWhenStarting", false);

            profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/excel");

And I’m getting the following mistake:

inserir a descrição da imagem aqui

  • 2

    You will not be able to do this with this window. Because it is Windows and Selenium is limited to the browser. You can try to create some options to save to a specific directory

  • @You can edit the browser options to download automatically in a directory. But when you reopen your browser with Firefoxdriver the settings won’t hold!

  • @Thanks for the tips! I switched the Webdriver to Chromedriver, and got the automatic download in the default Downloads folder!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.