Is it possible to upload file attachment with selenium in Python script?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If there is a form with file input on the page, I think it's straightforward to fill value in the input and submit the form with python api of selenium. You can find some sample code on the document page
回答2:
It can be done via:
element = driver.find_element_by_name("file")
element.send_keys("/home/pavel/Desktop/949IH3GNHAo.jpg")
回答3:
button = driver.find_element_by_xpath("xpathToYourButton")
button.send_keys("fullPathToFile")
Now if you are in windows path to file uses backslash. To avoid issues use double backslashes! C:\ \Users\ ****\ \Desktop\ \1.jpg without spaces.
PS. I know its a from 4 years ago but I have been trying to figure this out for some time and someone might find this usefull...
回答4:
it is quite simple, just record it using IDE. Upload command is working