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
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Adarsh
  • 13
  • 1
  • 6
  • 1
    Looks like you have `send_keys("upload")` when you should have `send_keys(upload)` without the quotes. – David Buck Jun 10 '20 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 : – Adarsh Jun 10 '20 at 22:58
  • sir i think i am using wrong slash / , \ which one should i use . i checked from all ways.. thank you – Adarsh Jun 10 '20 at 23:02

2 Answers2

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:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
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";

Dazed
  • 1,527
  • 1
  • 13
  • 25