猿问

selenium.common.exceptions.InvalidArgument

当我使用此代码时,使用 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


慕田峪9158850
浏览 364回答 2
2回答

翻阅古今

你已经足够接近了。您不想传递字符序列上传,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";
随时随地看视频慕课网APP

相关分类

Python
我要回答