Selenium Python FirefoxWebDriver处理打开保存对话框
代码如下(网上示例):
#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处理打开保存对话框的更多相关文章
- Qt__文件打开保存对话框(QFileDialog)
转自豆子空间 使用QFileDialog有两种方法,一种是比较简单的使用"静态函数法",另一种是可以自定义各个细节的"构造函数法". 静态函数法 修改MainW ...
- selenium python 设置窗口打开大小
1. 窗口最大化 1 driver.maximize_window() 2. 设置窗口大小 1 driver.set_window_size(1920,1080) #分辨率1920 x 1080
- java中文件保存、打开文件对话框
package com.soft.test; //AWT: FileDialog类 + FilenameFilter类 可以实现本功能 //Swing: JFileChooser类 + FileFil ...
- C#对话框-打开和保存对话框(转)
//打开文件 OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.In ...
- C#线程安全打开/保存文件对话框
在多线程单元模式(MTA)中为应用程序使用.NET OpenFileDialog和SaveFileDialog 下载FileDialogsThreadAppartmentSafe_v1.zip 如果您 ...
- MFC打开/保存文件对话框:CFileDialog
MFC打开/保存文件对话框:CFileDialog CFileDialog 文件选择对话框的使用:首先构造一个对象并提供相应的参数,构造函数原型如下: CFileDialog::CFileDial ...
- selenium + python 自动化测试环境搭建
selenium + python 自动化测试 —— 环境搭建 关于 selenium Selenium 是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操 ...
- [译]Selenium Python文档:目录
作者:Baiju Muthukadan 协议:本文档采用知识共享署名 - 共享4.0国际许可. 原英文网址:http://selenium-python.readthedocs.io/index.ht ...
- [译]Selenium Python文档:二、初步开始
2.1.简单使用 如果已经安装好了Selenium Python,你就可以像下面这样编写Python代码来使用它了: from selenium import webdriver from selen ...
随机推荐
- 【opencv基础】imwrite函数与图像存储质量
前言 std::vector<int> compression_params; compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); ...
- JavaBasic_06
二维数组 二维数组定义格式 格式1 数据类型 变量名 = new 数据类型m; m表示这个二维数组有多少个一维数组 n表示每一个一维数组的元素个数 格式2 灵活性 数据类型 a = new 数据类型m ...
- NHibernate many-to-one映射
many-to-one 数据方面,多条对一条. 非主键字段与主键字段的关联,在类中实现了一对一的单向映射.在类中是单实体映射. 订单充值业务.显然,一单位可以有多个充值信息. 通过表 Deposit里 ...
- CFG文件格式
大多数情况下,很多程序都要保存用户的设置,办法有很多:注册表,日志文件·..... 而很多程序都使用了一个专用的文件.为了方便起见,常常命名为*.cfg,有时甚至直接命名为Config.cfg. 这只 ...
- epoll c++封装
#ifndef _BFC_EPOLL_FLOW_HPP_ #define _BFC_EPOLL_FLOW_HPP_ #include <string.h> #include <err ...
- CodeForces - 1100F:Ivan and Burgers (线性基&贪心)(离线 在线)
题意:给定N个数,Q次询问,求区间最大异或和. 思路:一开始想的线性基+线段树.单次线性基合并的复杂度为20*20,结合线段树,复杂度为O(NlogN*20*20):显然,超时. 超时代码: #inc ...
- POJ 2456: Aggressive cows(二分,贪心)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20485 Accepted: 9719 ...
- 2018.4.23 git常用操作命令收集(转)
Git常用操作命令收集: 1. 远程仓库相关命令 检出仓库:$ git clone git://github.com/jquery/jquery.git 查看远程仓库:$ git remote -v ...
- L2-008 最长对称子串 (25 分)
对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定Is PAT&TAP symmetric?,最长对称子串为s PAT&TAP s,于是你应该输出11. 输入格式: 输入在一 ...
- springboot+kotlin+springcloud+java+grade+maven混编?
springboot + maven + java vs springboot + gradle + kotlin 快速搭建:https://start.spring.io/ springclould ...