在没有< input type =“文件">的情况下上传硒文件.元素 [英] selenium file upload without <input type="file"> element

查看:92
本文介绍了在没有< input type =“文件">的情况下上传硒文件.元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试通过硒/python在此处上传我的简历,在简历/简历附加"部分下.

I'm trying to upload my resume using selenium/python over here , under the Resume/CV Attach part.

当我检查Attach元素时,它显示为<a data-source="attach" href="#">Attach</a>.

When I inspect the Attach element, it shows up as <a data-source="attach" href="#">Attach</a>.

我对HTML不太熟悉,因此我尝试通过xpath查找元素,使用send_keys()上载文件,但它在程序中运行并且不上载任何内容.没有错误消息.

I'm not too familiar with HTML so I've tried finding the element by xpath, using send_keys() to upload the file but it runs through the program and doesn't upload anything. No error messages.

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)

我可以设法找到Web元素,并使用click()打开上载文件选项,但我希望能够完全上载文件.

I can manage to find the web element and use click() to open the upload file options up but I want to be able to fully upload a file.

当输入type="file"时,好像是在线上传的示例,该输入我以前使用过并且可以正常工作.

It seems like the example online upload when the input type="file", which I've used before and works fine.

推荐答案

实际上有一个用于文件上传的输入.您可以使用以下代码:

Actually there is an input for file uploading. You can use below code:

driver.find_element_by_id('file').send_keys(info.resume)

请注意,所有3个文件输入字段(CV,求职信和成绩单的非官方副本)都具有相同的id属性"file",因此您可以按索引选择每个字段:

Note that all 3 file input fields (CV, Cover letter and Unofficial copy of your transcript) have the same id attribute "file", so you can select each by index:

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)

这篇关于在没有&lt; input type =“文件"&gt;的情况下上传硒文件.元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆