简体   繁体   中英

Webdriver io, file upload using input type=“file”

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?

file_path = browser.uploadFile(FILE_PATH)
# Путь к загружаемому файлу на устройстве
$('div.my_selector').setValue(file_path)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM