当我使用这段代码时,在Selenium中使用Python上传文件时,它给出了错误,有人能帮助我吗?
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"。