Created
January 31, 2019 17:41
-
-
Save livelace/f91320a539784e67636d55191559c0b3 to your computer and use it in GitHub Desktop.
Take a screenshot of a Grafana dashboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions | |
BROWSER_PATH = "/usr/bin/google-chrome-stable" | |
BROWSER_DRIVER_PATH = "/usr/local/bin/chromedriver" | |
def main(url, filename): | |
browser_options = webdriver.ChromeOptions() | |
browser_options.add_argument("--headless") | |
browser_options.binary_location = BROWSER_PATH | |
driver = webdriver.Chrome( | |
executable_path=BROWSER_DRIVER_PATH, | |
chrome_options=browser_options | |
) | |
driver.set_window_size(1920, 1080) | |
driver.get(url) | |
try: | |
element = WebDriverWait(driver, 30).until( | |
expected_conditions.presence_of_element_located((By.CLASS_NAME, "dashboard-container")) | |
) | |
screenshot = element.screenshot_as_png | |
f = open(filename, "wb") | |
f.write(screenshot) | |
f.close() | |
except Exception as e: | |
print("ERROR: {}".format(e)) | |
sys.exit(1) | |
if __name__ == "__main__": | |
if len(sys.argv) < 3: | |
print("Usage: {} <dashboard_url> <screenshot_file_path>".format(sys.argv[0])) | |
sys.exit(1) | |
else: | |
main(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment