我正在尝试使用 selenium/python 通过 here 上传我的简历,在 Resume/CV Attach 部分下。
当我检查 Attach 元素时,它显示为 <a data-source="attach" href="#">Attach</a>.
我不太熟悉 HTML,所以我尝试通过 xpath 查找元素,使用 send_keys()
上传文件但它通过程序运行并且不上传任何内容。没有错误消息。
driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div[3]/form/div[1]/div[10]/div/div[3]/a[1]').send_keys(info.resume)
我可以设法找到网络元素并使用 click()
打开上传文件选项,但我希望能够完全上传文件。
输入type="file"
时好像在线上传的例子,我以前用过并且工作正常。
最佳答案
其实还有一个文件上传的输入。您可以使用以下代码:
driver.find_element_by_id('file').send_keys(info.resume)
请注意,所有 3 个文件输入字段(简历、求职信和成绩单的非官方副本)都具有相同的 id
属性 "file"
,因此您可以选择每个按索引:
driver.find_elements_by_id('file')[0].send_keys(info.resume)
driver.find_elements_by_id('file')[1].send_keys(info.cover_letter)
driver.find_elements_by_id('file')[2].send_keys(info.transcript)
关于javascript - 没有 <input type ="file"> 元素的 Selenium 文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51888388/