栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

具有下载功能的无头浏览器测试?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

具有下载功能的无头浏览器测试?

您可以做的是:

  • 启动 虚拟显示 (请参阅Xvfb)
  • Firefox
    使用配置为 自动保存 文件的 首选项启动浏览器
    csv

__带有附加注释的python中的 工作示例
(使用pyvirtualdisplay

xvfb
包装器):

from os import getcwdimport timefrom pyvirtualdisplay import Displayfrom selenium import webdriver# start the virtual displaydisplay = Display(visible=0, size=(800, 600))display.start()# configure firefox profile to automatically save csv files in the current directoryfp = webdriver.FirefoxProfile()fp.set_preference("browser.download.folderList", 2)fp.set_preference("browser.download.manager.showWhenStarting", False)fp.set_preference("browser.download.dir", getcwd())fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv")browser = webdriver.Firefox(firefox_profile=fp)browser.get('http://www.nationale-loterij.be/nl/onze-spelen/lotto/resultaten')# check the optionbrowser.find_element_by_id('corporatebody_3_corporategrid93961a8f9b424ed6bd0697df356d9483_1_rblType_0').click()# click the linkbrowser.find_element_by_name('corporatebody_3$corporategrid93961a8f9b424ed6bd0697df356d9483_1$btnDownload').click()# hardpred delay for waiting a file download (better check for the downloaded file to appear on the disk)time.sleep(2)# quit the browserbrowser.quit()# stop the displaydisplay.stop()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/452295.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号