selenium file upload without <input type=“file”> element

有些话、适合烂在心里 提交于 2020-01-04 02:34:06

问题


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

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

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)

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.

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


回答1:


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

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

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)


来源:https://stackoverflow.com/questions/51888388/selenium-file-upload-without-input-type-file-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!