我具有以下用于文件上传的HTML。
<div class="drop-zone hand-cursor ng-pristine ng-untouched ng-valid ng-empty" ngf-select="" ngf-drop="" data-ngf-pattern=".pdf" data-ngf-accept="application/pdf" data-ng-model="vm.siteVo.signed_order_form">
<!-- ngIf: !vm.siteVo.signed_order_form -->
<div ng-if="!vm.siteVo.signed_order_form" class="ng-scope"><i class="material-icons primary-color font-size-40">backup</i>
<br><span class="color54 font-size-16 ng-binding">Drag and drop file here or click to open explorer</span></div>
<!-- end ngIf: !vm.siteVo.signed_order_form -->
<!-- ngIf: vm.siteVo.signed_order_form -->
</div>
我尝试了以下查找
driver.find_element_by_css_selector(".drop-zone > .ng-scope").send_keys("file path")
但出现以下错误
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=77.0.3865.90)
答案 0 :(得分:0)
已解决:input
与type
file
不在同一个div
中,而是随机放置在页面中。使用xpath找到它并直接使用send_keys()