问题
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