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 ...
随机推荐
- 【leetcode】7-ReverseInteger
problem: Reverse Integer 注意考虑是否越界: INT_MAX INT_MIN 32bits or 64bits 调整策略,先从简单的问题开始:
- C#读取文件夹下所有指定类型,并返回相应类型数据
C#读取文件夹下所有文件 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享.心 ...
- HTML5的一些知识点
1.新增很多api,比如获取用户的地理位置的window.navigator.geoloaction,history,audio,video,canvas 2.websocket;websocket是 ...
- 两道不错的递推dp
hdoj-4055 #include <cstdio> #include <cstring> #include <iostream> #include <al ...
- apache 和 php 整合、apache配制虚拟机
如何 把apache 和 php 整合起来 ? (关闭防火墙或在防火墙内添加80端口,关闭selinux) 修改:apache的配制文件:/usr/local/apache2.4/conf/h ...
- 特殊符号 sort_wc_uniq命令 tee_tr_split命令
* 任意个 任意字符 ? 任意一个字符 # 注释字符 \ 转意符 | 管道符 (之前有说过) cut 命令: cut -d "&quo ...
- ideal通过svn上传项目和激活方式
激活方式: http://www.ideadev.club/topic/detail/102?anchor=1526259147353#1526259147353
- IntelliJ IDEA备忘
IntelliJ IDEA生成get/set方法的快捷键 IntelliJ IDEA生成get/set有2种方式,alt+enter.alt+insert.下面分别介绍这2种方式快速生成get与set ...
- 【jar包删除,再添加版本更高的jar】******.jar in project cnnot be read or is not a valid
把4.2.0删除,然后添加其他版本的jar包
- 统计cpu相关信息
我的cpu为i3310m 适用类型:笔记本 CPU系列:酷睿i3 3代系列 CPU主频:2.4GHz 三级缓存:3MB 插槽类型:FCBGA1023,FCPGA988 封装大小:37.5×37.5mm ...