繁体   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