Created
March 22, 2017 17:48
-
-
Save kantoniak/a7df65f25f0622ce5f62a53893e6a699 to your computer and use it in GitHub Desktop.
Goes to Sketchpad website and draws a pattern
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/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