代码如下(网上示例):

#profile =  webdriver.FirefoxProfile(r"C:\Users\Skyyj\AppData\Roaming\Mozilla\Firefox\Profiles\1rzh6139.default")
profile = webdriver.FirefoxProfile()

##设置成0代表下载到浏览器默认下载路径;设置成2则可以保存到指定目录
profile.set_preference("browser.download.folderList", 2)
#这里设置与否不影响,没有发现有什么影响。
#profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", r"c:\Down")
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
#这里设置与否没有发现有什么影响
#profile.set_preference("browser.helperApps.alwaysAsk.force", False);
self.driver = webdriver.Firefox(profile)

自己写的实例(Environment:Python3.6.5+Selenium+PyCharm+Firefox61+FirefoxDriver)

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time,os

profile = webdriver.FirefoxProfile()

#save the file to directory=E:\sli\CIFS2
profile.set_preference("browser.download.dir", r"E:\sli\CIFS2")
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)

#download .zip file
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/zip")

#driver = webdriver.Firefox(firefox_profile=profile)
driver = webdriver.Firefox(profile)

driver.get("http://10.49.5.8:8080/RLink/login.jsp")
driver.maximize_window()
# -----------------------------------Login Steps----------------------------------------------
# input user name
driver.find_element_by_id("j_username").send_keys("1")
time.sleep(1)
# input password
driver.find_element_by_id("j_password").send_keys("1")
time.sleep(1)
# click "Log in" button
driver.find_element_by_id("buttonSubmit").click()
time.sleep(1)

# -----------------------------------Download Steps----------------------------------------------
# Highlight a zip file by xpath
driver.find_element_by_xpath("/html/body/div[6]/div[2]/div/div[7]/div/div/div[3]/div/div[4]/div/div[4]/div/div/div/div/div/ul/li[10]/div/table/tbody/tr[1]/td/div/div/div/table/tbody/tr/td/div/div/img").click()
time.sleep(2)
# click "Download" button
driver.find_element_by_xpath("/html/body/div[6]/div[2]/div/div[5]/div/table/tbody/tr/td[1]/table/tbody/tr/td[2]/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div").click()
time.sleep(2)

# -----------------------------------Logout Steps----------------------------------------------
# click "下拉框" of user menu
driver.find_element_by_xpath('/html/body/div[6]/div[2]/div/div[5]/div/table/tbody/tr/td[2]/table/tbody/tr/td/div/table/tbody/tr/td[2]/table/tbody/tr/td[2]/img').click()
time.sleep(1)
# click "Log Out"
driver.find_element_by_xpath("//div[text()='Log Out']").click()
time.sleep(1)
# click "Yes" on confirm dialog
driver.find_element_by_xpath('/html/body/div[9]/div/div/div/div[3]/div/div[2]/button[1]').click()
# click "No" on confirm dialog
#driver.find_element_by_xpath('/html/body/div[9]/div/div/div/div[3]/div/div[2]/button[2]').click()
time.sleep(1)
driver.quit()

												

Selenium Python FirefoxWebDriver处理打开保存对话框的更多相关文章

  1. Qt__文件打开保存对话框(QFileDialog)

    转自豆子空间 使用QFileDialog有两种方法,一种是比较简单的使用"静态函数法",另一种是可以自定义各个细节的"构造函数法". 静态函数法 修改MainW ...

  2. selenium python 设置窗口打开大小

    1. 窗口最大化 1 driver.maximize_window() 2. 设置窗口大小 1 driver.set_window_size(1920,1080) #分辨率1920 x 1080

  3. java中文件保存、打开文件对话框

    package com.soft.test; //AWT: FileDialog类 + FilenameFilter类 可以实现本功能 //Swing: JFileChooser类 + FileFil ...

  4. C#对话框-打开和保存对话框(转)

    //打开文件            OpenFileDialog openFileDialog = new OpenFileDialog();            openFileDialog.In ...

  5. C#线程安全打开/保存文件对话框

    在多线程单元模式(MTA)中为应用程序使用.NET OpenFileDialog和SaveFileDialog 下载FileDialogsThreadAppartmentSafe_v1.zip 如果您 ...

  6. MFC打开/保存文件对话框:CFileDialog

    MFC打开/保存文件对话框:CFileDialog CFileDialog   文件选择对话框的使用:首先构造一个对象并提供相应的参数,构造函数原型如下: CFileDialog::CFileDial ...

  7. selenium + python 自动化测试环境搭建

    selenium + python 自动化测试 —— 环境搭建 关于 selenium Selenium 是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操 ...

  8. [译]Selenium Python文档:目录

    作者:Baiju Muthukadan 协议:本文档采用知识共享署名 - 共享4.0国际许可. 原英文网址:http://selenium-python.readthedocs.io/index.ht ...

  9. [译]Selenium Python文档:二、初步开始

    2.1.简单使用 如果已经安装好了Selenium Python,你就可以像下面这样编写Python代码来使用它了: from selenium import webdriver from selen ...

随机推荐

  1. mac上不了网

    不知怎么回事勾选了socks代理导致ping的通但打不开网页软件登不了

  2. UGUI中Event Trigger的基本用法

    UGUI中Event Trigger的基本用法 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chin ...

  3. django安装命令

    通过pip安装Django   ==指定版本号 pip install Django==2.0.2 查看djangoshifou安装成功:1.进入python ,2.import   django 查 ...

  4. CSS3 transform变形(2D转换)

    transform 属性应用于2D 或 3D 转换.该属性允许我们对元素进行平移.旋转.缩放或倾斜. 一.translate(x,y).translateX(n).translateY(n)定义2D平 ...

  5. 单调栈的运用-bzoj1012(代码转载-http://hzwer.com/1130.html)

    Description 现在请求你维护一个数列,要求提供以下两种操作: . 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. . 插 ...

  6. CSS3动画那么强,requestAnimationFrame还有毛线用

    http://www.zhangxinxu.com/wordpress/2013/09/css3-animation-requestanimationframe-tween-%E5%8A%A8%E7% ...

  7. 51Nod 1240:莫比乌斯函数

    1240 莫比乌斯函数  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使 ...

  8. HDU2023:求平均成绩

    Problem Description 假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量. ...

  9. 博客 first

    2016.10.28 这会是一个值得纪念的日子,我将会从此刻开始,1~2天不间断的更新我再软件,编程方面的学习历程和在大学的琐事. 希望N年后看到,能够回味. a good memery....... ...

  10. 2017.4.5 Strom

    Strom是分布式实时计算系统,它对于实时计算的意义类似于hadoop对于批处理的意义.与Storm关系密切的语言:核心代码用clojure书写,实用程序用python开发,使用java开发拓扑. S ...