通过Selenium在AngularJS中自动上传文件
Automate file upload in AngularJS via Selenium
我正在使用Powershell驱动.NET Selenium和FirefoxDriver来自动化一些东西。其中一部分是文件上传,网站恰好(至少部分)使用AngularJS编写。
现在,我已经了解了如何使用普通输入元素自动上传文件。只需通过SendKeys发送文件路径。
但在这种情况下我想不通。带有可选手动文件选择器的文件放置区域的HTML如下所示:
<div class="overflowHidden video-drop-zone file-drop-zone zone appversionicon rounded"
ng-file-drop="onFileSelect($files);" ng-file-drop-available="dropSupported=true">
<div class="simpleDropZoneFileSelect">
<span class="selectFileText">
<span class="ng-binding ng-hide" ng-show="dropLabel !== undefined && dropLabel !== ''"><br></span>
<a class="ng-binding" href="" ng-show="true">Select file</a>
<input class="" ng-show="true" ng-file-select="onFileSelect($files)" type="file">
</span>
</div>
</div>
我希望我没有把这件事简化太多。整个AngularJS设置肯定不止于此。但也许你给我一些建议就足够了,告诉我下一步该往哪里看,或者如何解决这个问题。如果没有,请告诉我,我会添加更多信息。
我发现Protractor似乎是进行AngularJS测试的方法,但它会大大改变我的设置(使用NodeJS服务器等),我现在只需要上传这个文件。
谢谢!
Sandro
不确定整个设置是什么样子的。但文件上传在硒中要容易得多。
Driver.FindElement(By.CssSelector("input[type='files']")).SendKeys("FilePath")
应该这样做
<button class="btn btn-primary ng-scope" ng-click="vm.importAccountsClicked()" translate="import-accounts">Import Accounts</button>
<input class="hide" type="file" id="fileItem" accept=".csv" onchange="angular.element(this).scope().import()">
我在使用Webdriver和Java时遇到了类似的问题。查看一个带有"导入帐户"按钮的网页(上面的html片段),我无法让Selenium+Java向其发送密钥。我所做的错误是没有使用type=file属性来识别元素。相反,我使用的是按钮的文本:
@FindBy (xpath="(//button[.='Import Accounts'])")
private WebElement importbutton;
所以在我将importbutton变量声明更改为之后
@FindBy (id = "fileItem")
private WebElement importbutton;
使用sendKeys()方法解决了该问题。
importbutton.sendKeys(filepath);
希望这能有所帮助。
相关文章:
- 如何使用post方法从方法上传文件
- 使用Angular和Node上传文件
- 使用Angular js-量角器e2e测试上传文件
- 点击Angularjs中的按钮上传文件
- S3文件上传文件对象使用节点js
- AJAX上传文件不起作用
- 如何一键录音并自动上传
- jQuery使用$.post上传文件
- 使用node-js上传文件,并将表单信息存储在数据库(mysql)中
- 如何禁用dropzone's自动上传文件
- 输入标签 - 自动上传文件
- 通过Selenium在AngularJS中自动上传文件
- 如何在文件自动上传时禁用Dropzone.js中的提交表单
- 在事件上使用jQuery,而不是在插件文件上传器上自动上传
- 我们可以从一个路径自动完成上传文件吗
- PHP AJAX多个文件并选择后自动上传
- 自动生成PDF文件,并自动上传到服务器
- 如何使用jQuery自动打开上传文件对话框
- 拖放文件,但不要自动上传
- JS:自动上传文件到表单