0
I am crawling a web page and there comes a time when I need to upload a file, this Crawler is to test a system. What I need to do is with the pure javascript inputar a document on the following page:
<label for="avatar">Choose a profile picture:</label>
<input type="file"
id="avatar" name="avatar"
accept="image/png, image/jpeg">
Does anyone know how to do that ?
Thanks in advance.
You want a script that accesses this URL and sends a predetermined file to the server that hosts this page, that’s what you want?
– MagicHat
There is no way to input files from the client’s machine, if this were possible it would be one of the biggest security loopholes that a browser would have.
– Guilherme Nascimento
Missing the main, the code you already have! Using what? Puppeteer? Phantomjs? Selenium? Anyway, you need the code you already have.
– Gleidson Henrique
I use a class that was developed with dryscrap , I already have the code that navigates the page and fills normal fields , this class I use has a function that allows you to run pure javascript on the screen, this javascript that I use to fill the fields, however simulating a file is complicated, with Puppeteer I can go up because it already has a function of its own.
– Felipe Tolentino
In Puppeteer it would be like this
var findelement = await page.$("#file"); 
 await findelement.uploadFile("teste.pdf"); //Caminho do arquivo relativo ao script.
– Felipe Tolentino