1

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?

1

2 Answers 2

2

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!

1
  • Thank you very much! Four years later, thanks to you, I finally found a great solution to my problem! addValue works even with invisible inputs
    – Paganini
    Commented Jun 12 at 6:48
1

I had similar issue, For Me setValue() showed error :element not interactable And addValue() Worked.

const filepath = path.join(process.cwd(),'path/to/file');
const input = await $("//input[@type='file']")
const remoteFilePath  =  await browser.uploadFile(filepath)
await input.addValue(remoteFilePath)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.