Mar*_*ars 7 selenium headless-browser phantomjs casperjs
我一直在寻找在osx中进行无头测试的解决方案.但我需要能够保存服务器返回的文件.
我测试了selenium,phantomjs,casperjs,并研究了我能在网上找到的任何东西.
他们都不支持下载.我错过了什么吗?有没有支持下载的无头浏览器/测试框架?
你能做的是:
Firefox浏览器并配置自动保存csv文件的首选项python 中的工作示例带有附加注释(使用pyvirtualdisplay xvfb包装器):
from os import getcwd
import time
from pyvirtualdisplay import Display
from selenium import webdriver
# start the virtual display
display = Display(visible=0, size=(800, 600))
display.start()
# configure firefox profile to automatically save csv files in the current directory
fp = 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 option
browser.find_element_by_id('corporatebody_3_corporategrid93961a8f9b424ed6bd0697df356d9483_1_rblType_0').click()
# click the link
browser.find_element_by_name('corporatebody_3$corporategrid93961a8f9b424ed6bd0697df356d9483_1$btnDownload').click()
# hardcoded delay for waiting a file download (better check for the downloaded file to appear on the disk)
time.sleep(2)
# quit the browser
browser.quit()
# stop the display
display.stop()
Run Code Online (Sandbox Code Playgroud)
也可以看看:
| 归档时间: |
|
| 查看次数: |
5911 次 |
| 最近记录: |