为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 196 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信