gpt4 book ai didi

python - selenium webdriver上传文件

转载 作者:太空狗 更新时间:2023-10-29 18:28:01 24 4
gpt4 key购买 nike

我是 selenium 的新手,我有一个将文件上传到服务器的脚本。

在 ide 版本中它会上传文件,但是当我将测试用例导出为 python 2/unittest/webdriver 时它不会上传它..

它没有给我任何错误,只是没有上传...

python 脚本是:

driver.find_element_by_id("start-upload-button-single").click()
driver.find_element_by_css_selector("input[type=\"file\"]").clear()
driver.find_element_by_css_selector("input[type=\"file\"]").send_keys("C:\\\\Documents and Settings\\\\pcname\\\\Desktop\\\\ffdlt\\\\test.jpeg")

我搜索了解决方案,但除了将它与 AutoIt 或 AutoHotKey 集成外,我还没有找到其他解决方案...

第一行打开Firefox的文件上传框。

最佳答案

您的代码非常适合我(我使用 Firefox、Chrome 驱动程序对其进行了测试)

我怀疑的一件事是过多的反斜杠 (\) 转义。

尝试以下操作:

driver.find_element_by_id("start-upload-button-single").click()
driver.find_element_by_css_selector('input[type="file"]').clear()
driver.find_element_by_css_selector('input[type="file"]').send_keys("C:\\Documents and Settings\\pcname\\Desktop\\ffdlt\\test.jpeg")

driver.find_element_by_id("start-upload-button-single").click()
driver.find_element_by_css_selector('input[type="file"]').clear()
driver.find_element_by_css_selector('input[type="file"]').send_keys(r"C:\Documents and Settings\pcname\Desktop\ffdlt\test.jpeg")

关于python - selenium webdriver上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18823139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com