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:
/
or \\
.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)
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.