Selenium入门9 上传文件

上传文件步骤

1 找到文件上传的input标签 

find_element_by_css_selector("input[type='file']")

2 用send_keys传入本地文件位置信息

用淘宝首页搜索框的上传图片试一下

#coding=utf-8
#上传文件

from selenium import webdriver
import time

dr=webdriver.Firefox()
dr.get("http://www.taobao.com")
time.sleep(2)
#上传文件 dr.find_element_by_css_selector(
"input[type='file']").send_keys('D:\1.jpg') #第一个转义符 time.sleep(2) dr.quit()
原文地址:https://www.cnblogs.com/dinghanhua/p/9738611.html