selenium+python send_keys() 上传文件
2016-04-10 16:17
771 查看
selenium+python 上传文件
使用send_keys()方法,跟一个本地的文件路径,到达上传文件目的。
(备注:该例子是根据‘虫师’例子做了补充)
upload_file.html
script:
在这里主要强调的是绝对路径与相对路径的使用。
虫师文献:
selenium借助AutoIt识别上传(下载)详解
/article/4666324.html
使用send_keys()方法,跟一个本地的文件路径,到达上传文件目的。
(备注:该例子是根据‘虫师’例子做了补充)
upload_file.html
<html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>upload_file</title> <script type="text/javascript" async="" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" /> <script type="text/javascript"> </script> </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://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script> </html>
script:
#-*-coding:utf-8-*- from selenium import webdriver import os import time driver = webdriver.Firefox() file_path = 'file:///'+os.path.abspath('upload_file.html') driver.get(file_path) #使用send_keys('绝对路径')方法上传文件 #driver.find_element_by_name('file').send_keys('C:\Users\Think\Pictures\file\note_book.jpg') #使用send_keys('相对路径')方法上传文件 driver.find_element_by_name('file').send_keys('C:\\\Pictures\\note_book.jpg') time.sleep(2) driver.quit()
在这里主要强调的是绝对路径与相对路径的使用。
虫师文献:
selenium借助AutoIt识别上传(下载)详解
/article/4666324.html
相关文章推荐
- python列出指定文件夹下所有给定后缀名的文件
- python:mysql查询
- python --yield
- 解析python中的类:
- 【python日常一】使用python抓取拉勾网职位信息并做简单统计分析
- python错误汇总3:安装MySQLdb时:EnvironmentError: mysql_config not found
- 一、Python 进阶 之 函数式编程
- caffe用python时可能需要的模块安装
- python中隐式的内存共享
- python中隐式的内存共享
- Python贴吧小爬虫
- Head First Python 学习札记 2016-04-09
- python练习_12
- odoo8新API multi 装饰类详解
- python:获取mysql版本
- python基础练习(二)—— 数据分析包numpy数组操作
- python中np.random.randint()
- 探究Ubuntu14.04下多版本Python下连接MySQL数据库的安装
- Python中print()函数中的一些参数
- [python之数据分析] 基础篇1- Numpy,Scipy,Matplotlib 快速入门攻略