猿问

无法使用 Selenium 上传文件

我有以下用于文件上传的 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)


江户川乱折腾
浏览 102回答 1
1回答

阿波罗的战车

已解决:inputwithtype&nbsp;file不在同一个div页面中,而是随机放置在页面中。使用 xpath 定位并直接使用send_keys()
随时随地看视频慕课网APP

相关分类

Python
我要回答