简体   繁体   中英

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found error while uploading file using Selenium Python

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

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 ie either / or \\
  • Add the file extension, eg .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:

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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found error invoking send_keys() using Selenium selenium.common.exceptions.InvalidArgumentException: Message: invalid argument error invoking get() using Selenium Webdriver through Python selenium.common.exceptions.InvalidArgumentException: Message: invalid argument error invoking get() with urls read from text file with Selenium Python selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'cookie' while adding cookies using selenium webdriver selenium.common.exceptions.InvalidArgumentException: Message: File not found while trying to upload image by url through selenium selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'ELEMENT' error when switching frame in Selenium selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'using' must be a string using waits and expected conditions URL must be a string selenium - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'url' must be a string selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use error with real Chrome Browser Is CssSelector the only way I can use for shadowroot? selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM