如何使用量角器控制 Windows 文件选择器 [英] How can I control the windows File Selector using protractor

查看:33
本文介绍了如何使用量角器控制 Windows 文件选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我点击了一个上传按钮,它会打开一个 Windows 文件选择器.我无法使用量角器在该文件选择器对话框中写入文件路径.

I am clicking on a upload button which opens up a windows file selector. I am not able to write the path to a file in that File Selector dialog using protractor.

我尝试通过在量角器中传递 ctrl+v 按键来将文本复制到剪贴板并将其粘贴到文件上传.能够复制文本但粘贴不起作用.

现在我打算使用 robotsjs 或其他一些工具来实现这一点.
知道我们如何在量角器中做到这一点吗?

I tried copying the text to the clipboard and pasting the same to File Upload by passing ctrl+v keypress in protractor. Able to copy the text but paste is not working.

Now I am planning to use robotjs or some other tool to achieve this.
Any idea how can we do this in protractor?

推荐答案

你试过了吗?

// set file detector
var remote = require('../../node_modules/protractor/node_modules/selenium-webdriver/remote');
browser.setFileDetector(new remote.FileDetector());


var fileToUpload = '../sample.txt';
var absolutePath = path.resolve(__dirname, fileToUpload);

var fileElem = element(by.css('input[type="file"]'));

// Unhide file input
browser.executeScript("arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px';  arguments[0].style.opacity = 1", fileElem.getWebElement());

fileElem.sendKeys(absolutePath);

// take a breath 
browser.driver.sleep(100);

// click upload button
element(by.css('button[data-ng-click="uploadFile(file)"]')).click(); // does post request

请检查 this了解更多信息.

Please check this and this to more information.

希望这会有所帮助.:)

Hope this helps. :)

这篇关于如何使用量角器控制 Windows 文件选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆