javascript - 没有 <input type ="file"> 元素的 Selenium 文件上传

标签 javascript python python-2.7 selenium automation

我正在尝试使用 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 - 没有 &lt;input type ="file"> 元素的 Selenium 文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51888388/

相关文章:

python 解释器键被交换

无需 CLI 即可运行的 Python 脚本不采用命令行参数

python - 在电子邮件中包含 cron 作业脚本输出

javascript - 寻找匹配 URL 片段第一部分的正则表达式

javascript - 经常更新值时闪烁

javascript - pdf.js 下载为 document.pdf 而不是文件名

python - 将对象数组存储到 session Python

javascript - 在加载新页面时保持 Tab 始终处于事件状态

python - 将函数映射到子列表python的一部分

python - 如何在python中打印一次每个循环的所有结果