I am writing tests on CoffeeScript using Webdriver.io and mocha. The code is processed using the CoffeeScript compiler.
In the process, I needed to upload a file to the server using the input type = "file" (display: none) element.
I try to transfer the file address as follows (of course, first making it visible: style.display = 'block'):
elem_input = $('div.class_1 input.class_2')
browser.elementSendKeys(elem_input.elementId, '/home/user/ ... /test.txt')
The file cannot be found, the error message "File not found" appears in the console.
I carefully checked the path, it is correct. If you upload the file directly through the interface, manually, there are no problems either.
What could be the reason for this situation and what could be the solutions to the problem?
You want to use addValue
on your input[] element. My understanding is that setValue
clears existing values first before adding your new value (usually in a string context) whereas addValue
just adds the value directly, and since there are no values to clear from the input field since input type is file, you get :element not interactable
from setValue
.
Try that out and let me know if it works!