当我使用此代码时,使用 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)
四季花海
TA贡献1811条经验 获得超5个赞
你使用什么语言?
对于 c#,如果路径有效,请使用 @ 符号并使用 \
string upload= @"C:\Users\Archi\Downloads\resume testing\Resume testing";
添加回答
举报
0/150
提交
取消