from selenium import webdriver
import time ,os
driver =webdriver.Chrome()
file_path='file:///'+os.path.abspath('./webdriver_api/web_page/upfile.html')
driver.get(file_path)
#定位上传按钮,添加本地文件
driver.find_element_by_name("file").send_keys("C:\\Users\Administrator\AppData\Local\Programs\Python\Python35-32\webdriver_api\web_pageupload_file.txt")
time.sleep(5)
driver.quit()
16.Selenium2 自动化测试实战-基于Python语言-上传文件
最新推荐文章于 2024-09-29 13:57:14 发布
本文介绍了一种利用Selenium WebDriver进行网页自动化操作的方法,特别关注于如何通过Python脚本定位并模拟用户上传文件的过程。该示例展示了如何启动Chrome浏览器、加载指定的HTML页面并选择本地文件进行上传。
920

被折叠的 条评论
为什么被折叠?



