当我使用此代码时,使用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
答案 0 :(得分:0)
您使用什么语言?
对于c#,如果路径有效,则使用@符号并使用\
string upload = @“ C:\ Users \ Archi \ Downloads \ Resume testing \ Resume testing”;
答案 1 :(得分:0)
你足够亲密。
您不想通过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)
您可以在以下位置找到相关的讨论