-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2048.py
More file actions
27 lines (25 loc) · 866 Bytes
/
2048.py
File metadata and controls
27 lines (25 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# python3
# Write a program that will open the game at https://gabrielecirulli.github.io/2048/ and keep sending up
# right, down, and left keystrokes to automatically play the game
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.implicitly_wait(20)
browser.get('https://gabrielecirulli.github.io/2048/')
EntirePage = browser.find_element(By.TAG_NAME, 'html')
while True:
EntirePage.send_keys(Keys.UP)
time.sleep(1)
EntirePage.send_keys(Keys.RIGHT)
time.sleep(1)
EntirePage.send_keys(Keys.DOWN)
time.sleep(1)
EntirePage.send_keys(Keys.LEFT)
time.sleep(1)
try:
retryButton = browser.find_element(By.CLASS_NAME, 'retry-button')
break
except:
continue