Selenium WebDriver 上传输入类型为 "text" 的文件

Selenium WebDriver Upload File With Input Type of "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 20 python 3.8 chrome 91.0.4472.114 硒 3.141.0

更新: 我在下面找到了类型为“文件”的输入字段,但它位于页面底部。 (不在预期的模态内) 传递该元素的路径成功(没有selenium错误),但上传过程仍然失败。

<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 提供的语法最终使它起作用。