Selenium第16课 文件上传下载

一、PyKeyboard方法

  from pykeyboard import PyKeyboard

  from pymouse import PyMouse

  k = PyKeyboard()

  # k.press_key(k.enter_key)

  # k.release_key(k.enter_key)

  k.tap_key(k.enter_key)  # 下载文件时点击enter键

 

二、浏览器配置

  浏览器设置下载时不弹窗:about:config --> browser.download.folderList --> 0桌面,1默认路径,2指定目录

  profile = webdriver.FirefoxProfile()

  profile.set_preference('browser.download.folderList', 2)  # 下载时不弹窗

  profile.set_preference('browser.download.dir', 'd:\\')  # 下载到指定路径

  profile.set_preference('browser.download.manager.showWhenStarting', False)  # 不显示下载进度条

  profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')  # 下载后指定类型的文件不询问

  driver = webdriver.Firefox(firefox_profile=profile)

  dirver.get("www.")  # 打开一个有下载的网页

  driver.find_element_by_id("id").click()  # 点击立即下载

  

三、AutoIt上传文件 

  1.官网下载安装:http://www.autoitscript.com/site/

  用于非input输入框文件上传

  2.用到的功能

  SciTE Script Editor 编写脚本

  AutoIt Windows Info 定位Windows控件信息

  Run Script 执行脚本

  Compile Script to.exe 生成exe文件

  3.例子:脚本内容

  WinActivate("文件上传");

  ControlSetText("文件上传", "", "Edit1", $CmdLine[1]);

  sleep(2000);

  ControlClick("文件上传", "", "Button1");

  运行:tools --> go  试试有没有问题,转化为exe,cmd窗口试试

  4.python代码中执行生成的exe文件

  import os

  path = r"c..exe"  # exe文件路径

  os.system(path)  # 执行exe文件

  5.AutoIt命令行参数

  $CmdLine[0] 参数的个数,$CmdLine[1] 第一个参数

  cmd执行时,直接在后面加 空格文件路径

  python中:

  fp = r"D:\111.jpg"  # 图片命名不要用中文

  os.system(r"C:...exe %s" % fp)

   

  

 

 

  

posted @ 2019-02-24 16:05  雨之印迹  阅读(133)  评论(0编辑  收藏  举报