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

北慕城南 提交于 2019-12-03 16:28:57

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

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