Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Goes to Sketchpad website and draws a pattern
#!/usr/bin/python
import time
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.webdriver.common.action_chains import ActionChains
def draw_lines(action, offsets, scale=1):
for o in offsets:
action.click_and_hold()
action.move_by_offset(scale * o[0], scale * o[1])
action.release().perform()
page = u'https://sketch.io/sketchpad/'
driver = webdriver.Chrome()
driver.set_window_size(700, 500)
driver.set_window_position(50, 50)
driver.get(page)
# Close welcome popup
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#alertify .icon-close')))
time.sleep(0.2)
driver.find_element_by_css_selector('#alertify .icon-close').click()
print "Start drawing..."
# Start mouse interactions
action = ActionChains(driver)
action.move_to_element(driver.find_element_by_tag_name('sketch-document')).perform()
draw_lines(action, [(-30, 60), (30, 40), (30, -40), (-30, -60)])
draw_lines(action, [(60, -30), (40, 30), (-40, 30), (-60, -30)])
draw_lines(action, [(-30, -60), (30, -40), (30, 40), (-30, 60)])
draw_lines(action, [(-60, -30), (-40, 30), (40, 30), (60, -30)])
draw_lines(action, [(-30, 60), (30, 40), (30, -40), (-30, -60)], 0.8)
draw_lines(action, [(60, -30), (40, 30), (-40, 30), (-60, -30)], 0.8)
draw_lines(action, [(-30, -60), (30, -40), (30, 40), (-30, 60)], 0.8)
draw_lines(action, [(-60, -30), (-40, 30), (40, 30), (60, -30)], 0.8)
draw_lines(action, [(-30, 60), (30, 40), (30, -40), (-30, -60)], 0.6)
draw_lines(action, [(60, -30), (40, 30), (-40, 30), (-60, -30)], 0.6)
draw_lines(action, [(-30, -60), (30, -40), (30, 40), (-30, 60)], 0.6)
draw_lines(action, [(-60, -30), (-40, 30), (40, 30), (60, -30)], 0.6)
print "Done."
time.sleep(20)
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.