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 ...
随机推荐
- Sublime 修改快捷键
Preferences-Key Bindings-User 添加一行: { "keys": ["ctrl+d"], "command": & ...
- windows apache "The requested operation has failed" 启动失败
找到失败原因,进入cmd(win+r快捷键,输入cmd)命令行下 进入到你的apache bin目录下: 每个人错误可能不同,根据自己问题去相应改
- ELFhash
字符串哈希算法(以ELFHash详解) 更多字符串哈希算法请参考:http://blog.csdn.net/AlburtHoffman/article/details/19641123 先来了解一 ...
- hdu2732 Leapin' Lizards 最大流+拆点
Your platoon of wandering lizards has entered a strange room in the labyrinth you are exploring. As ...
- hdu1875 畅通工程再续 并查集/最小生成树
相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全 ...
- 学习笔记TF013:卷积、跨度、边界填充、卷积核
卷积运算,两个输入张量(输入数据和卷积核)进行卷积,输出代表来自每个输入的信息张量.tf.nn.conv2d完成卷积运算.卷积核(kernel),权值.滤波器.卷积矩阵或模版,filter.权值训练习 ...
- python------模块定义、导入、优化 ------->Yaml, l模块
一. yaml模块 用来做配置文件. 需要pip安装该包. 二. ConfigParser模块 用来生成和修改常见配置文件,在python3.x版本中更名为configparser. (什么是配置文件 ...
- 通信协议演进与JCE协议详解
一.通信协议概述通信协议是两个节点之间为了协同工作.实现信息交换,而协商的规则和约定,例如规定字节序,各个字段类型,使用什么压缩算法或加密算法等. 1.原始数据假设A和B通信,获取或设置用户基本资料, ...
- navicat连接oracle方法及其安装包
Navicat破解版下载(安装好之后,点击执行最后一个破解文件即可) 链接: https://pan.baidu.com/s/1pMpVwfT 密码: vrt6 连接oracle还需要下载以下文件,o ...
- Centos7安装teamviewer 32/64位
centos7安装teamviewer teamviewer安装包,自己去官网下吧,不用找了,估摸着就没有Centos7 64位的 所以直接下centos teamviewer 32位那个rpm包吧 ...