'Problem passing file to an input-type-file webelement

How to set File objects and length property at FileList object where the files are also reflected at FormData object?

I was trying to use the hack described in the link above to insert through code the file I want to upload to an '<input type='file', but I am having trouble to implement it.

I am using the following code as a snippet in Chrome devtools Console Panel:

inp = document.querySelector("input[type=file]");
const dT = new DataTransfer();
dT.items.add(new File(['foo'], 'C:\\Users\\MyUser\\Desktop\\SomeFolder\\MyTestFile.txt'));
inp.files = dT.files;

The input text that should display only the file name shows the full path, and when I press the button to upload the file it return an error saying that the file was not founded.

I already check the path and it is 100% right. I don't know much about javascript, in fact I am using Selenium to do the rest of the automation, but this particular subject looks like can only be achieved with js.

Could anyone help me? Am I mising something or did I misunderstood the hack solution and what I am trying to do is not possible at all?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source