如何使用量角器上传文件

编程入门 行业动态 更新时间:2024-10-27 04:36:46
本文介绍了如何使用量角器上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个需要上载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

更多推荐

如何使用量角器上传文件

本文发布于:2023-11-23 03:37:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619941.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:量角器   如何使用   上传文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!