简体   繁体   English

Webdriver io,使用输入类型=“文件”上传文件

[英]Webdriver io, file upload using input type=“file”

I am writing tests on CoffeeScript using Webdriver.io and mocha .我正在使用Webdriver.iomochaCoffeeScript上编写测试。 The code is processed using the CoffeeScript compiler.使用 CoffeeScript 编译器处理代码。

In the process, I needed to upload a file to the server using the input type = "file" ( display: none ) element.在此过程中,我需要使用input type = "file" ( display: none ) 元素将文件上传到服务器。

I try to transfer the file address as follows (of course, first making it visible: style.display = 'block' ):我尝试如下传输文件地址(当然,首先使其可见: 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用angularjs在输入type = file之前验证文件大小 - validate file size before upload for input type=file using angularjs 在sendKeys触发上传后,通过输入的WebDriver文件上传冻结 - WebDriver file upload through input freezes after sendKeys triggers the upload 使用输入类型=文件在IE中为第一个文件无效的文件上传,适用于后续上传 - File upload using input type=file not working in IE for first file, works on subsequent uploads 从输入类型=文件上传图像到服务器 - Upload image to server from input type=file 使用单独的上载按钮修改的输入类型文件 - input type file modified with separate upload button 使用Selenium Webdriver自动上传文件 - Automating File Upload with Selenium Webdriver 无法使用Selenium Webdriver中的send_keys上传文件 - Unable to Upload File using send_keys in Selenium Webdriver 使用Selenium Webdriver中的Flash按钮(* .swf)上传文件 - file upload using flash button(*.swf) in Selenium webdriver 使用Selenium HtmlUnitDriver-headless webdriver上传文件 - File Upload using Selenium HtmlUnitDriver-headless webdriver Selenium Webdriver:如何使用他的相对路径上传文件(javascript) - Selenium Webdriver : How to upload file using his relative path (javascript)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM