繁体   English   中英

如何使用 selenium 和 Python 上传文件

[英]How can I upload using File using selenium and Python

我想上传一个文件:

<button id="interior-file-upload-browse-button-announce" class="a-button-text" type="button">
Upload Interiorr manuscript
</button>

我尝试使用此解决方案,但它不起作用:

browser.find_element_by_id("interior-file-upload-browse-button announce").send_keys("/Users/maclab/Desktop/Design/scale/interior.pdf")

我不知道为什么你的不起作用,如果没有错误跟踪,很难说出问题所在。 这是另一种解决方案。 使用Fine-uploader ,使用 pytest 运行 selenium 测试:

    elm = driver.find_element_by_xpath("//input[@type='file']")
    elm.send_keys(os.getcwd() + "/tests/sample_files/Figure1.tif")

在我的情况下,不需要表单提交或 Enter 键。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM