-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling File Input Dialogs #2946
Comments
If there is something like which could keyboard.type into the file dialog and press enter, that would do the trick. We can accomplish this using different node packages that generate keyboard events at operating system level, but, that requires the browser to always be in focus. So, is there something like this possible in Puppeteer? |
@KJ1i Puppeteer generally operates on the web page level; we don't support the fileinput dialog and instead "override" it with How's the file input dialog opened? Maybe I'll be able to come up with a workaround for your case. |
@aslushnikov Thanks for replying! Here is the image of the website upload button:- When we click on Browse button, it opens up the file dialog and, then, after selecting the file in the file dialog, it fills the The following is the website:- http://www.createspace.com I have asked this question on StackOverflow also:- https://stackoverflow.com/questions/51491928/uploading-a-file-on-non-input-type-file Please let me know if more details are needed. Awaiting your reply. |
I have a similar problem. I use a custom plugin I think this is a very common practice to upload file, but I can't use puppeteer to resolve it. Please give some help for me. |
Also having the same problem as @KJ1i where clicking on an element opens a native dialog (and it's not input[type="file"]). |
@KJ1i @cloudZQY @HawkiesZA this is indeed poorly supported atm; I failed to come up with any reasonable workaround for you guys. For this to work properly, we need to expose more events from DevTools procol, similarly how we did it with javascript dialogs. Please upvote the issue to bump its priority. We rely on "likes" to figure what's most important to do next. |
sounds like a must have feature, most sites these days tend to use alternative file upload controls instead of the common file input |
I would really like to see this feature supported soon ! |
This support is something which I am in need too, any plan to provide a fix on this? |
Seems that for my specific case, I was able to work it out:
Here's a naive example: await page.waitForSelector('.file-dialog-trigger')
await page.click('.file-dialog-trigger')
const input = await page.$('input[type="file"]')
await input.uploadFile('./content.csv') |
need this feature badly! |
I also work it out using your way. |
Looking forward for this feature. Also have this issue! |
Any progress on this? |
I second the need for this. I am writing a fuzz tester for our app. Works great, but I'd love to be able to upload a generic image whenever a file dialog appears. This would be a sweet API:
|
I confirm this is much needed |
Is there any progress on this? me and my team would love for this feature to be implemented. |
Agreed, this would be nice for testing server google cloud server deployments of Drupal, Wordpress, and others just to make sure files can be uploaded properly. |
Actions are performed, but the file is not loaded. Why not working? |
@Ermolaev-Nikolay try using another selector for |
@slmgc, thank you for the answer, but seems the problem in another. It seems the photo is loaded, but instead of the edit window goes to main page. |
Anybody solve it? Thanks |
This roll includes: - https://crrev.com/673121 - DevTools: intercept file chooser requests References puppeteer#2946
@sekreiner I have the same problem. |
I'm having the same issue. I cannot send an image to a facebook input [type=file]. Did anyone figured it out ? |
if you you youse some kind of upload library (react-dropzone in my case) you can try to trigger a change event on the input after uploading the file. await page.waitForSelector('input[type=file]'); this did the trick for me |
@robinjoerke 's solution works like a charm for me. Thanks for sharing! |
@robinjoerke , thanks! At last somebody found a solution that is working. |
Thanks, it works. |
This code works very well thanks, but I have a problem, event object received by my event listener doesn't have a file type when I trigger a change event. Like this event.target.files[0].type = "". Normally, event.target.files[0].type should have a value like event.target.files[0].type = "image/png". |
@robinjoerke's code looks a bit hackish but has anyone actually managed to use the fileChooser API (waitForFileChooser and accept) or is it broken? |
As I said I was using an upload library, I was not noticing this issue (library somehow just ignored this). But backend always recieved contentType "application/octet-stream". Should have been something as "image/png" as well. This might be an effect of the issue you have. What I do to fix this is just guess the content type from the file extension part of the filename. Not a nice solution but works for my testing scenarios. |
I think the biggest problem is that the file will be sent as I have searched around a lot but I cannot figure out how to set content-type for the multipart header. Even tried to upload via XHR after setting the file with |
Thanks a lot!!! It works for me. |
this works without click on the button and without a remaining open windows from the browser |
You saved my life man!!!! |
This works for me:
|
How do you close the dialog? |
using that code, the dialog there is no pop up dialog appear. it automatically upload the file without open file dialog |
Simplest example: const fileInput = await page.$('#file-input')
await fileInput.uploadFile(filename) If a button spawns the input dialog: const [fileInput] = await Promise.all([page.waitForFileChooser(), page.click("#file-input")])
await fileInput.accept([filename]) |
Is there any way to handle File Input Dialogs?
When I click an element on the page, it opens up the upload file dialog.
I can not use
elementHandle.uploadFile
as it is not aninput[type="file"]
. Plus, #1376 will not help as, dragging and dropping in the file upload field does not work, instead, dragging and dropping opens up the file in the browser tab.I am using Windows, so there won't be the problem where, file dialog behavior is different across operating systems.
So, can you provide some example code on how would I go about doing that? Thanks!
The text was updated successfully, but these errors were encountered: