亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

selenium.common.exceptions.InvalidArgument

selenium.common.exceptions.InvalidArgument

慕田峪9158850 2023-01-04 16:51:03
當我使用此代碼時,使用 Python 在 Selenium 中上傳文件會出錯,有人可以幫我解決這個問題嗎?from selenium import webdriverfrom selenium.webdriver.common.keys import Keysdriver=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 testingC:\Users\Archi\Downloads\resume testing/Resume testingC:\\Users\Archi\Downloads\resume testing/Resume testing
查看完整描述

2 回答

?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

你已經足夠接近了。

您不想傳遞字符序列上傳,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)


查看完整回答
反對 回復 2023-01-04
?
四季花海

TA貢獻1811條經驗 獲得超5個贊

你使用什么語言?

對于 c#,如果路徑有效,請使用 @ 符號并使用 \

string upload= @"C:\Users\Archi\Downloads\resume testing\Resume testing";


查看完整回答
反對 回復 2023-01-04
  • 2 回答
  • 0 關注
  • 285 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號