Selenium网络驱动程序上传输入类型为"text"的文件



我正试图将文件上传到表单中,但没有类型为"的输入元素;文件";。

我可以删除";只读";属性并将键发送到输入文本框,但当我单击上传按钮时,它会抛出一个一般错误。(只是一个没有有用信息的弹出窗口(

这就是呈现的元素:

<input type="text" autocomplete="off" class="form-control animate-show 
ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" 
id="filepath" ng-model="model.name" ng-required="configuration.Required" 
readonly="" required="required" style="">

这是手动选择文件后的元素:

<input type="text" autocomplete="off" class="form-control animate-show 
ng-pristine ng-touched ng-not-empty ng-valid ng-valid-required" 
id="filepath" ng-model="model.name" ng-required="configuration.Required" 
readonly="" required="required" style="">

这是去除";只读";并通过selenium:发送我的文件路径

<input type="text" autocomplete="off" class="form-control animate-show 
ng-touched ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required" 
id="filepath" ng-model="model.name" 
ng-required="configuration.Required" required="required" style="">

测试设置:Ubuntu 20python 3.8铬91.0.4472.114硒3.141.0

更新:我发现下面的输入字段的类型是";文件";,但它位于页面的底部。(不在预期模态范围内(将路径传递到此元素是成功的(没有硒错误(,但上载过程仍然失败。

<label tabindex="-1" style="visibility: hidden; position: absolute; 
overflow: hidden; width: 0px; height: 0px; border: none; margin: 0px; 
padding: 0px;">upload<input type="file" ngf-select="" 
ng-model="model" ng-show="!model"></label> 
"upload" 
<input type="file" ngf-select="" ng-model="model" ng-show="!model"> 
<label tabindex="-1" style="visibility: hidden; position: absolute; 
overflow: hidden; width: 0px; height: 0px; border: none; margin: 0px; 
padding: 0px;">upload 
<input type="file" ngf-select="" ng-model="model" ng-show="!model">
</label>

原来有一个类型为"的元素;文件位于页面的其他部分。访问正确的元素并使用带有文件路径的send_keys非常有效。有问题的原始文本框中填充了文件名,并且文件上传正确。

感谢大家的投入,尤其是@YaDavMaNish的语法最终使它发挥了作用。

最新更新