本文介绍了如何使用量角器上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个需要上载JPEG图像的量角器脚本.我可以单击上载按钮,这将打开Windows文件选择器.但是,然后我需要使用量角器在该文件选择器"对话框中写入文件的路径.
I'm writing a protractor script that need to upload a JPEG image. I could click on the upload button which opens up a windows file selector. But, then I need to write the path to a file in that File Selector dialog using protractor.
但是,我不知道它是如何工作的.我尝试仅使用sendKeys键入路径,但到目前为止还行不通.
But, i have no idea how it works. I tried just typing the path using sendKeys and it doesn't work so far.
任何人都知道如何执行此操作吗?
Anyone have an idea how to do this?
谢谢. :)
推荐答案在"如何使用量角器控制Windows File Selector ".
如果您需要快速解决方案,请尝试以下解决方案:
If you need a quick solution try the following solution:
// 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更多推荐
如何使用量角器上传文件
发布评论