SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.75k stars 8.2k forks source link

Download without confirmation on Firefox Linux (javascript generated file) #9692

Closed hildogjr closed 3 years ago

hildogjr commented 3 years ago

Environment

OS: Ubuntu 20.04 Browser: Firefox Browser version: 90.0 (64-bit) Browser Driver version: GeckoDriver 0.29 Language Bindings version: Python 3.8 Selenium Grid version (if applicable): 3.141.0

Expected behaviour

I want to automatic download some XLSX file from a webpage using Python without Firefox ask me for confirmation. I tried the Selenium tutorial as bellow:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

opts = Options()

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.dir', MY_PATH)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',
                       'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
                       ';application/vnd.ms-excel'
                       ';application/xls'
                       ';application/xlsx')

browser = webdriver.Firefox(profile, options=opts, executable_path=DRIVER_PATH)
browser.get('https://filesamples.com/formats/xlsx')
btn = browser.find_elements_by_class_name('btn-primary')
btn[0].click()

Wrong behaviour

This code works fine in the used above site. The problem is when I use in my company website where the file is generated through a JavaScript action (the click action generate a process windows, at the end the file is asked to be saved).

<a id="executarAnaliseForm:accordionAnalise:_btnExportarXlsxCustom" href="#" title="Excel" onclick="jsf.util.chain(this,event,'PrimeFaces.monitorDownload(beforeExport, afterExport);','mojarra.jsfcljs(document.getElementById(\'executarAnaliseForm\'),{\'executarAnaliseForm:accordionAnalise:_btnExportarXlsxCustom\':\'executarAnaliseForm:accordionAnalise:_btnExportarXlsxCustom\'},\'\')');return false">

image

image

How to make the given profile act in this download? Is this a bug or a missing configuration mine?

ghost commented 3 years ago

๐Ÿ‘‹ Hi there! Thank you for creating this issue.

I am the Selenium Assistant Bot ๐Ÿค–, I triage issues in this repository. If I can't do it, I label it to help maintainers identify issues that need triaging.

I am an Open Source project ๐Ÿ™Œ, post bugs or ideas here!

ghost commented 3 years ago

โ—๏ธ It seems this issue is not using any of the supported templates

๐Ÿ’ก Supported issue types are (they start with):

Issue templates help this project to stay in shape, please use them and fill them out completely. By doing that you are helping the project because the community and maintainers can provide prompt feedback, and potentially solve the issue.

If you are asking a question, a better way to address this is:

If you think this is incorrect, please feel free to open a new issue.

hildogjr commented 3 years ago

It is not allowed to re-open the closed issue, @SeleniumHQ / @selenium-assistant.

The question is also on StackOverflow: https://stackoverflow.com/questions/68567548/download-file-generated-by-javscript-without-confirmation-using-firefox-linux-pl

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.