
[英]selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found error invoking send_keys() using Selenium
[英]selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found error while uploading file using Selenium Python
当我使用此代码时,使用 Python 在 Selenium 中上传文件时出错,有人可以帮我吗?
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")
错误:
selenium.common.exceptions.InvalidArgumentException:消息:无效参数:找不到文件:上传
即使我也从这种方式检查过,然后也显示错误。
C:/Users/Archi/Downloads/resume testing/Resume testing
C:\Users\Archi\Downloads\resume testing/Resume testing
C:\\Users\Archi\Downloads\resume testing/Resume testing
你离得够近了。
您不想通过send_keys()
传递字符序列上传,而是想传递文件C://Users/Archi/Downloads/resume testing/Resume testing
因此,您需要进行两(2)项更改,如下所示:
/
或\\
.doc
因此,您的有效代码块将是:
upload="C:\\Users\\Archi\\Downloads\\resume testing\\Resume testing.doc"
driver.find_element_by_id("file-upload").send_keys(upload)
您可以在以下位置找到相关讨论:
您使用什么语言?
对于 c#,如果路径有效,请使用 @ 符号并使用 \
string upload= @"C:\Users\Archi\Downloads\resume testing\Resume testing";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.