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?
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.
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