Home > Software engineering >  Download finish dialog mozilla selenium ubuntu
Download finish dialog mozilla selenium ubuntu

Time:10-10

I have a problem with a python script using selenium with mozilla firefox . When the scripts download the file i want and finish the process , mozilla open me the download dialog saying that download is finished on my right upper corner of the window . I need to close that window but i couldnt achieve it to close the window and finish the script.

What could i do?

from selenium import webdriver
import unittest
from selenium.webdriver.common.keys import Keys
import time
import requests
#################################################################################

options = webdriver.FirefoxOptions()

options.set_preference("browser.download.manager.showAlertOnComplete", False)
options.set_preference("browser.download.panel.shown", False)
options.set_preference("browser.download.animateNotifications", False)
options.set_preference("browser.helperApps.alwaysAsk.force", False)
options.set_preference("browser.download.manager.showWhenStarting", False)

options.set_preference(
    "browser.helperApps.neverAsk.saveToDisk",
    (
        "application/pdf, application/zip, application/octet-stream, "
        "text/csv, text/xml, application/xml, text/plain, "
        "text/octet-stream, application/x-gzip, application/x-tar "
        "application/"
        "vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    ),
)

###############################################################################3
browser=webdriver.Firefox(options=options)
browser.get('http://10.1.0.100:4025/accounts/login/?next=/')

time.sleep(3)

id_box=browser.find_element("id","id_username")
id_box.send_keys('admin')

time.sleep(1)

pass_box=browser.find_element("id","id_password")
pass_box.send_keys('changeme')

time.sleep(1)
login_button = browser.find_element("name","submit")
time.sleep(1)
login_button.click()
time.sleep(1)
browser.get("http://10.1.0.100:4025/backup/list")

time.sleep(4)
generate_button=browser.find_element("id","generate")
generate_button.click()

alert = browser.switch_to.alert
try:
   alert.accept() #If you want to Accept the Alert
except:
   alert.dismiss()  #If  You want to Dismiss the Alert.



time.sleep(25)
browser.get("http://10.1.0.100:4025/backup/download/all")
time.sleep(5)
################################################

################################################
time.sleep(5)
browser.close()

CodePudding user response:

There are lots of ways of changing the default download behavior on Firefox. You can use the options below to prevent that download window from showing up at all:

from selenium import webdriver

options = webdriver.FirefoxOptions()

options.set_preference("browser.download.manager.showAlertOnComplete", False)
options.set_preference("browser.download.panel.shown", False)
options.set_preference("browser.download.animateNotifications", False)
options.set_preference("browser.helperApps.alwaysAsk.force", False)
options.set_preference("browser.download.manager.showWhenStarting", False)

options.set_preference(
    "browser.helperApps.neverAsk.saveToDisk",
    (
        "application/pdf, application/zip, application/octet-stream, "
        "text/csv, text/xml, application/xml, text/plain, "
        "text/octet-stream, application/x-gzip, application/x-tar "
        "application/"
        "vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    ),
)

driver = webdriver.Firefox(options=options)
  • Related