How to block the file chooser in Firefox? - selenium

I'm developing an application that uses Selenium for automation of a certain process that involves file upload.
There is a button on that website that executes some ajax which loads in the file input element, but also tries to open file chooser for some reason.
In Chrome it works fine - the file chooser is blocked (message from the console: File chooser dialog can only be shown with a user activation.).
The problem is that I can't block it in Firefox. I looked through about:config and found nothing useful.
So how do I block it?

Related

Firefox Ignores Content-Disposition

I'm trying to write MVC endpoint that will optionally set the content-disposition to inline or attachment in order to either display the file (a pdf) inside a new browser tab or else to download it. The UI allows the user to select how they'd like to open the file (not my design - can't change that aspect of it).
Note that this works in Chrome/Edge just as expected.
In Firefox, the application settings for PDF appear to trump the content-disposition. Is there a reliable way to get Firefox to respect the content-disposition? Preferably a way that will work w/ a vanilla installation of the browser such that end-users don't need to make any modifications on their end for it to work.
Here's the code I'm using to setup my response (class is derived from ApiController):
var response = Request.CreateResponse(System.Net.HttpStatusCode.OK);
response.Content = new PushStreamContent((stream, content, context) =>
{
dispatcher.Dispatch(request, stream);
}, new MediaTypeHeaderValue(MediaTypeNames.Application.Pdf));
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue(contentDisposition)
{
FileName = $"{auto_generated_fileName}.pdf",
};
response.Headers.CacheControl = new CacheControlHeaderValue()
{
NoCache = true,
NoStore = true
};
return response;
We have noticed this issue in our webapp as well. The webapp has a download button that lets the user download a PDF file. Firefox shows the PDF file in the current tab, which effectively kills the webapp.
After a bit of research, this appears to be an intentional feature, see the release notes for Firefox 98:
When you set an application to open files of a specific type in your Firefox preference settings, those files will open automatically, even files served by the website with "content-disposition: attachment". The same applies to PDF files that are set to open in Firefox by default. This is a fix to bug 453455.
Personally, while I can understand some users may want this for web pages that don't behave well, this is an issue for well-behaved web apps.
Setting the download attribute on the anchor does not appear to work either, Firefox still shows the file inline (tested with Firefox 99.0)
So as far as I am aware, you cannot force the browser to download the file if the browser does not allow it. Other web apps such as OwnCloud or Google Drive are having the same issue -- if you click right on a PDF file in Google Drive and then click on Dowload, Firefox still open the PDF file inline, whereas Chrome downloads it.
For now, it seems the best you can do is to open file in a new tab, to prevent the webapp or web page from being replaced by the downloaded file (which is also what Google Drive seems to be doing). You can open the download in a new tab or window e.g. via the target attribute on an <a> links or via the formtarget atttribute on a <button> element.
I found #blutorange's answer after trying to find a solution to the same problem as OP. However, just before I got here, I stumbled across this answer from back in 2013 - https://stackoverflow.com/a/16515146 which suggests to set the Content-Type header to application/octet-stream, instead of application/pdf.
I tried that solution and what do you know - it works! The PDF opens in a new tab in Firefox automatically, but at least it doesn't replace the tab of my application, so yay! Chrome doesn't seem to mind it either and my PDF viewer on my computer also recognizes the files as PDFs.
Now, this might not be the most "correct" fix to the issue we're facing, but it's an alternative to forcing open a new tab.

How does one enable the developer console in Safari for Outlook Add-in Dialog API?

I am working on an add-in that is failing to load scripts via the Dialog API.
The template from the HTML renders correctly in the Dialog. If I render the template in the main TaskPane, both the HTML and the scripts execute correctly.
I can see the console logs in the TaskPane, but the Dialog seems to be a bit of a black box. There's no logs, network, or DOM info that I can see. Is there a way to enable the Safari console for the Dialog?
**** UPDATED: ADDED GIF ****
(the gif slows down the flashing of the screen, but this what happens when attempting to open the inspector in the Dialog)

File Upload warning Chrome 66 and above to be handled using Selenium Webdriver

Chrome browser allows folder upload (using browse dialog) and recently post version 65 we are seeing a security popup which states that do you trust this site for uploading the files from folder.
This popup is causing the Automation to fail, is there any way to handle it using Selenium? like by using certain capability to bypass it or clicking it?
I already tried Alert accept/dismiss but it doesn't work as it seems that its not an alert. I also tried UIAutomation but it seems that elements are enclosed within the browser without any classname/ID's.
For the time being I have given a workaround of sending Keyboard Tab key and Enter keys.
Is there a proper way to bypass this dialog?
Any help will be appreciated.
Pop-Up Dialog screenshot

Can't upload file from browser. RobotFramework, Selenium + Autoit on remote host

I have read many posts with similar problem but I didn't find any solution.
In my tests I'm uploading some files - after click on button in app in browser system shows window 32770 (opening or browse). I'm using AutoIt library for RobotFramework to handle upload action by this system window. Everything works perfectly until I run it on remote hosts (windows slave computer) and terminal's screen is covered.
Has anybody met and solved such an issue?
The most common way of uploading files with Selenium2Library is to use the Choose File keyword, which bypasses the need to interact with a popup dialog.
Please use this
choose file(locator,Path)
locator: Location of element where you click to upload image
Path: Path of image
Put your image is working directory.

How to download internet(http) file in SL4 out of browser project?

my function open a internet page in pop-up browser before to download a file. But after I change to SL4 and out-of-browser, seems the pop-up is no longer working
System.Windows.Browser.HtmlPage.PopupWindow(_uri, "Report", null);
and then I also tried HttpWebRequest and WebBrowser. Seems they both won't ask the user to download the file or not, but just stay silence.
Finally, I sloved this by checking when OOB mode, use Shell command for the http URL, then a download box will prompt directly.