Skip to content

Latest commit

 

History

History
70 lines (46 loc) · 1.63 KB

screenshot.rst

File metadata and controls

70 lines (46 loc) · 1.63 KB

Take screenshot

Splinter can take a screenshot of the current view:

python

browser = Browser()
screenshot_path = browser.screenshot('absolute_path/your_screenshot.png')

You should use the absolute path to save a screenshot. If you don't use an absolute path, the screenshot will be saved in a temporary file.

Take a full view screenshot:

python

browser = Browser()
screenshot_path = browser.screenshot('absolute_path/your_screenshot.png', full=True)

Take element screenshot

If the element is in the current view:

python

browser = Browser()
browser.visit('http://example.com')
element = browser.find_by_xpath('xpath_rule').first
screenshot_path = element.screenshot('absolute_path/your_screenshot.png')

If the element is not in the current view:

python

browser = Browser()
browser.visit('http://example.com')
element = browser.find_by_xpath('xpath_rule').first
screenshot_path = element.screenshot('absolute_path/your_screenshot.png', full=True)

Take html snapshot

Splinter can also take a snapshot of the current HTML:

python

browser = Browser()
screenshot_path = browser.html_snapshot('absolute_path/your_screenshot.html')