Python Selenium无法找到用于上传文件的正确元素



用于"选择一个文件";按钮

<input name="ctl00$PlaceHolderMain$UploadDocumentSection$ctl05$InputFile" type="file" id="ctl00_PlaceHolderMain_UploadDocumentSection_ctl05_InputFile" class="ms-fileinput ms-fullWidth" size="35" onfocus="ResetSpFormOnSubmitCalled();" onchange="CheckAssetLibMediaExtension()" title="Choose a file">

Python代码

choose_file= browser.find_element_by_id('ctl00_PlaceHolderMain_UploadDocumentSection_ctl05_InputFile')
choose_file.send_keys(file_path)

但这对我不起作用。

一些技术堆栈会自动生成元素的id,并查看该id有多乱——它可能就是其中之一。因此,我建议使用不同的选择器。

如果只有一个文件上传按钮,这可能对你更好:

browser.find_element_by_css_selector('input.ms-fileinput')

最新更新