How to save page in Firefox, Chrome, PhantomJS with selenium webdriver?

烂漫一生 提交于 2019-12-05 01:14:49

问题


I want to save a web site and download file into specific folder. How can I do it with webdriver? In Chrome and Firefox I just press Ctrl+S then select a folder to save the current website. Is there any way to do it in selenium webdriver? Can PhantomJS do it?


回答1:


My conclusion is that you cannot do this with the current features of selenium.

Why? The two available features from Selenium that are relevant for your needs are:

  • taking screenshot
  • and retrieving the html source of the page

However those won't match what is done with a Ctrl+S.




回答2:


Automate pressing Control S then switch to the save menu and save the html file. Here's how I did it with Python:

    driver.send_keys("u'\ue009'"+"s")
    driver.switch_to.window("Window_ID")
    driver.find_element_by_id("SAVE_button").click()

Use the inspect tool to find the Window name and the necessary Id's.

see: http://selenium-python.readthedocs.org/api.html#selenium.webdriver.common.keys.Keys.CONTROL



来源:https://stackoverflow.com/questions/22368613/how-to-save-page-in-firefox-chrome-phantomjs-with-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!