1

When I use this code it gives error for file uploading in Selenium using Python , Can anyone help me with this?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver=webdriver.Chrome(executable_path="C:\\Users\Archi\PycharmProject\chrome driver\chromedriver")
driver.get("https://www.freshersworld.com/user/register")

driver.implicitly_wait(10)

upload="C://Users/Archi/Downloads/resume testing/Resume testing"
driver.find_element_by_id("file-upload").send_keys("upload")

Error:

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found : upload

Even I checked from this kind of ways also, then also its showing error.

  • C:/Users/Archi/Downloads/resume testing/Resume testing
  • C:\Users\Archi\Downloads\resume testing/Resume testing
  • C:\\Users\Archi\Downloads\resume testing/Resume testing
3
  • 1
    Looks like you have send_keys("upload") when you should have send_keys(upload) without the quotes. Commented Jun 10, 2020 at 20:39
  • thank you for making correct but when i remove quotes then also i get error selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found : Commented Jun 10, 2020 at 22:58
  • sir i think i am using wrong slash / , \ which one should i use . i checked from all ways.. thank you Commented Jun 10, 2020 at 23:02

2 Answers 2

3

You were close enough.

You don't want to pass the character sequence upload through send_keys() rather you want to pass the file C://Users/Archi/Downloads/resume testing/Resume testing

So you need to make two(2) changes as follows:

  • Use a distinct path separator i.e. either / or \\
  • Add the file extension, e.g. .doc

So, your effective code block will be:

upload="C:\\Users\\Archi\\Downloads\\resume testing\\Resume testing.doc"
driver.find_element_by_id("file-upload").send_keys(upload)

Reference

You can find a relevant discussion in:

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

1 Comment

thank you so much. now its working. i added file extension .docx
0

What language are you using?

For c#, If the path is valid, use the @ symbol and use \

string upload= @"C:\Users\Archi\Downloads\resume testing\Resume testing";

2 Comments

with python i am using
Not working for me on C#

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.