I'm new to Selenium Automated Testing and I'm just trying to do a simple task by typing in "hi" in the text box on a web page.
My code looks like this:
input = driver.find_element(By.XPATH, "//input[@type='file']")
input.send_keys('hi')
But when I run the code I received this error:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found : hi
Any ideas on how to fix this?
You first need to import "By"
from selenium.webdriver.common.by import By
input=driver.find_element(By.XPATH, '//input[@type="file"]')
input.send_keys("hi")
You can also write it in (although not suggested method to do )
from selenium.webdriver.common.by import By
driver.find_element(By.XPATH, '//input[@type="file"]').send_keys("hi")
This error message...
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found
...implies that the WebDriver instance was unable to find a file through the character sequence you have sent through send_keys()
.
The relevant HTML DOM would have helped us to debug your issue in a better way. Still it is clear from the Locator Strategy which you have used, that the expected content must be of type
as file
. Additionally it is possible, there is a JavaScript involved which checks the contents passed to the element if at all the contents refers to a valid file .
You need to pass a valid file as an argument with send_keys()
as follows:
driver.find_element(By.XPATH, "//input[@type='file']").send_keys("/path/to/filename.extension")
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.