2

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")
search.send_keys(Keys.RETURN) 

This error keeps showing up:

selenium.common.exceptions.WebDriverException: Message: File not found: D:/test.txt

The file is in place, where do you think the problem is?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Tried single and double backslashes and both failed.
I modified my answer, after I tried the code by myself with simple form with 2 input fields - file + submit.
Worked for me, Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.