Created
October 5, 2018 21:00
-
-
Save alexpreynolds/ff690d1c79ce95737508fe90fc4023e8 to your computer and use it in GitHub Desktop.
Selenium Python binding PNG export test
This file contains hidden or 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 | |
from selenium import webdriver | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.common.by import By | |
from selenium.common.exceptions import TimeoutException | |
import sys | |
import time | |
import base64 | |
chrome_options = webdriver.ChromeOptions() | |
chrome_options.add_argument('--headless') | |
chrome_options.add_argument('--no-sandbox') | |
chrome_options.add_argument('--disable-dev-shm-usage') | |
chrome_options.add_argument('--enable-webgl-image-chromium') | |
chrome_options.add_argument('--disable-application-cache') | |
driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver",chrome_options=chrome_options) | |
driver.set_window_size(1024,1280) | |
driver.get("http://explorer.altius.org/app/?config=SUFTOi4wT5S79NgyLKPTcg&chr=chr3&start=181500000&stop=181800000") | |
delay = 3 # seconds | |
try: | |
hg = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.CLASS_NAME, 'higlass'))) | |
time.sleep(10) | |
data = driver.execute_async_script(""" | |
var done = arguments[0]; | |
window.setTimeout(function(){ done( | |
window.higlassApi.exportAsPng() | |
); }, 1000); | |
""") | |
with open("localSeleniumTest.png", "wb") as fh: | |
fh.write(base64.b64decode(str(data.split(",")[1]))) | |
except TimeoutException: | |
sys.stderr.write("Error: Loading took too much time!") | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment