0

I have to download some file with selenium and I stuck on firefox download display.

I cannot change any of setting in selenium-webdriver, so i have to send arrow_down and enter to download display:

enter image description here

How should I do that?

Not sure that code matters but:

    def save_file(self):
        save_button = "save-file"
        send_button = "confirm"
        time.sleep(5)
        self.wait_for_visibility((By.ID, save_button))
        self.click_button(save_button)
        self.click_button(send_button)

It's two steps download procedure. 1st step: click button "save"

save button

2nd step: after first step there is additional confirmation.

confirm

language is of course python

7ek
  • 11
  • 2

1 Answers1

0

You can't interact with OS windows with selenium. What you could do is to tell Firefox to save the file without asking questions. Then you can find the file in the downloads folder.

You should start your Firefox with some extra parameters:

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)     
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain,text/html, application/xml");
driver = webdriver.Firefox(fp)

In case you want to specify a target location where to save, you can do it by:

fp.set_preference("browser.download.dir", **target_download_directory**)

EDIT:

In case "flying blind" is not an issue for your test/program, you can just press buttons and stuff like:

import pyautogui

pyautogui.press('down')
pyautogui.press('enter')

You need to pip install pyautogui first. Please note that in case any popup appears on screen (which takes focus), the code snippet above may not be enough. If I was you I'd use the first approach to make the program failsafe.

Trapli
  • 1,517
  • 2
  • 13
  • 19
  • Hi, Like I said, i cannot and i don't want to change any of parameters. The clue of whole thing is send 'arrow_down' and 'enter' to the pop-up display. I'm looking something like [this](https://stackoverflow.com/questions/29770599/how-to-download-docx-file-using-selenium-webdriver-in-java/29770750#29770750) – 7ek Mar 31 '20 at 04:06