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