![](/img/trans.png)
[英]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.