我正在编写一个需要上传 JPEG 图像的量角器脚本。我可以单击上传按钮,打开 Windows 文件选择器。但是,然后我需要使用量角器在文件选择器对话框中写入文件的路径。
但是,我不知道它是如何工作的。我尝试只使用输入路径sendKeys
到目前为止还不起作用。
有人知道如何做到这一点吗?
谢谢。 :)
试试我的回答“如何使用量角器控制 Windows 文件选择器 https://stackoverflow.com/questions/37153628/how-can-i-control-the-windows-file-selector-using-protractor/37156380#37156380".
如果您需要快速解决方案,请尝试以下解决方案:
// 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)