Skip to content Skip to sidebar Skip to footer

Failing To Upload A File Using Selenium

I'm trying to upload a file to a form using Selenium using this code on eclipse: search = driver.find_element_by_xpath('//input[@type='file']') search.send_keys('D:/test.txt') s

Solution 1:

I guess the reason is within the slash used in the path - I think it requires a backslash instead.

What if you try to use search.send_keys("D:\\test.txt")? Not sure if double backslash is required for that, so you can try with single one as well.

EDIT

I tried my own code on simple form with just the input[type=file] and with Submit button:

search = browser.find_element_by_xpath("//input[@type='file']")    
search.send_keys("F:\\test.txt")                                   
submit = browser.find_element_by_css_selector("input[type=submit]")
submit.click()

And somehow, it worked just fine, just had to escape backslash and to use Submit button instead of using ENTER button.

So make sure your file is actually there, within the path you posted, and such code (at least on Windows) works just fine. Also, you should make sure you have permission to this file.

Post a Comment for "Failing To Upload A File Using Selenium"