分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

selenium 文件上传

发布时间:2023-09-06 02:31责任编辑:郭大石关键词:文件上传selenium

 selenium文件上传

 通过input标签实现的上传功能,可将其看做是一个输入框,通过send_key()实现文件上传。

 创建一个test.html文件:

<html><head><meta http-equiv="content-type" content="text/html;charset=utf-8" /><title>upload_file</title><link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" /></head><body> ?<div class="row-fluid"> ???<div class="span6 well"> ???<h3>upload_file</h3> ?????<input type="file" name="file" /> ???</div> ?</div></body><script src="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js"></scrip></html>

网页效果:

通过以下代码进行文件上传:

from selenium import webdriverimport osdriver = webdriver.Firefox()file_path = ‘file:///‘ + os.path.abspath(‘upfile.html‘)driver.get(file_path)# 定位上传按钮,添加本地文件driver.find_element_by_name("file").send_keys(‘D:\\upload_file.txt‘)driver.quit()

selenium 文件上传

原文地址:https://www.cnblogs.com/aszeno/p/10317487.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved