Selenium Python FirefoxWebDriver处理打开保存对话框

摘要:
代码如下(在线示例):#profile=webdriver。Firefox Profile(r“C:UsersSkyyjAppDataRoamingMozillaFirefox Profiles1rzh6139.default”)Profile=webdriver Firefox Profile()##设置为0,这意味着下载到浏览器的默认下载路径;如果设置为2,则可以将其保存到指定的目录配置文件中。集合_首选

 代码如下(网上示例):

#profile =  webdriver.FirefoxProfile(r"C:UsersSkyyjAppDataRoamingMozillaFirefoxProfiles1rzh6139.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:sliCIFS2
profile.set_preference("browser.download.dir", r"E:sliCIFS2")
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处理打开保存对话框》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇配置Tomcat的server.xml编码为UTF-8时,再次发布项目,编码自动还原问题?公钥、私钥和数字签名(转载)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

最简方式 表格编辑 基于 el-table

共下面5点 1.新增一个显示和隐藏的参数 2.在显示那边新增一个input框,用v-model绑定数据,用v-if来显示和隐藏 3.给之前的显示的span标签添加v-else 和上面形成if else 4.编辑和保存按钮同理,然后编辑按钮触发的任务将所有输入打开。即seen置为true 5.保存按钮同理,保存按钮触发的任务将所有输入关闭。即seen置为fa...

ant-desin-vue——table全选时自定义的禁用行也被选上,且最后一行不选中问题

错误效果(序号1是获取数据后,初始化禁用的项):                                                        正确效果:                                                                                              ...

.Net Core应用框架Util介绍(五)

上篇简要介绍了Util在Angular Ts方面的封装情况,本文介绍Angular封装的另一个部分,即Html的封装。 标准组件与业务组件 对于管理后台这样的表单系统,你通常会使用Angular Material或Ng-Zorro这样的UI组件库,它们提供了标准化的UI组件。 标准组件将Ts封装起来,以特定标签和属性的方式提供使用。 业务组件使用标准组件拼...

element+vue显示数据库数据

App.vue <template><div class="app"><div id="heard"><h1>部门统计</h1></div><div id="Statistics"><div id="heard3"><h4>统计项</h4>...

selenium截屏操作(也支持截长图)

1.常用的可能是谷歌和火狐做自动化在抛异常的时候可以截屏保存 from selenium import webdriver br=webdriver.Chrome() br.maximize_window() br.get("https://www.cnblogs.com/Jack-cx/p/9383990.html") br.save_scree...

Selenium中日期控件的操作

有时页面为了防止用户修改指定的属性或者输入错误的格式,会对某些输入框设置readonly只读属性。一些日期选择框为了避免用户输入错误的格式,将输入框设置为只读,用户只能通过点击日期控件进行选择日期,如图5.11,网址为:http://www.miniui.com/demo/datepicker/datepicker.html 在使用日期控件通过点击选择日...