簡體   English   中英

selenium.common.exceptions.InvalidArgumentException:消息:無效參數:使用 Selenium 上傳文件時找不到文件錯誤 Python

[英]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.

相關問題 selenium.common.exceptions.InvalidArgumentException:消息:無效參數:使用 Selenium 調用 send_keys() 時未找到文件錯誤 selenium.common.exceptions.InvalidArgumentException:消息:使用 Selenium Webdriver 通過 Python 調用 get() 時參數無效錯誤 selenium.common.exceptions.InvalidArgumentException:消息:無效參數錯誤調用 get() 與使用 Selenium Python 從文本文件讀取的 url selenium.common.exceptions.InvalidArgumentException:消息:無效參數:使用 selenium webdriver 添加 cookie 時缺少“cookie” selenium.common.exceptions.InvalidArgumentException:消息:嘗試通過selenium通過url上傳圖像時找不到文件 selenium.common.exceptions.InvalidArgumentException:消息:無效參數:在 Selenium 中切換幀時缺少“元素”錯誤 selenium.common.exceptions.InvalidArgumentException:消息:無效參數:“使用”必須是使用等待和預期條件的字符串 URL 必須是字符串 selenium - selenium.common.exceptions.InvalidArgumentException:消息:無效參數:'url' 必須是字符串 selenium.common.exceptions.InvalidArgumentException:消息:無效參數:用戶數據目錄已在使用真正的 Chrome 瀏覽器時出錯 CssSelector 是我可以用於 shadowroot 的唯一方法嗎? selenium.common.exceptions.InvalidArgumentException:消息:無效參數:無效定位器
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM