Skip to content Skip to sidebar Skip to footer

How To Upload File Using Python+selenium?

I need to upload file. I have 'Choose file' form. I click 'Choose file' button, select file in window, after that uploading starts. Here is form.
Copy

Now after click on upload, add below code to pass address of file which need to be uploaded.

browser = webdriver.Firefox()
browser.get("url") 
time.sleep(10)
browser.find_element_by_id("fileUploadField").click()
shell = win32com.client.Dispatch("WScript.Shell")
shell.Sendkeys("D:\\FileLocation\\1.m4")
shell.Sendkeys("{ENTER}")

Note: In case you get any issue while installing win32com.client then check whether you have installed python for 32 bit os, if not then make sure you have installed python for 32 bit even if your os is 64 bit os. There won't be any problem in installation and win32com.client will work there

Solution 2:

Try setting full path:

driver.find_element_by_id("fileUploadField").send_keys(os.getcwd()+"/1.m4")

Post a Comment for "How To Upload File Using Python+selenium?"