forked from zylianyao/automate_online-materials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formFiller.py
71 lines (56 loc) · 2.62 KB
/
formFiller.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! python3
# formFiller.py - Automatically fills in the form.
import pyautogui, time
# Set these to the correct coordinates for your particular computer.
nameField = (648, 319)
submitButton = (651, 817)
submitButtonColor = (75, 141, 249)
submitAnotherLink = (760, 224)
formData = [{'name': 'Alice', 'fear': 'eavesdroppers', 'source': 'wand', 'robocop': 4, 'comments': 'Tell Bob I said hi.'},
{'name': 'Bob', 'fear': 'bees', 'source': 'amulet', 'robocop': 4, 'comments': 'n/a'},
{'name': 'Carol', 'fear': 'puppets', 'source': 'crystal ball', 'robocop': 1, 'comments': 'Please take the puppets out of the break room.'},
{'name': 'Alex Murphy', 'fear': 'ED-209', 'source': 'money', 'robocop': 5, 'comments': 'Protect the innocent. Serve the public trust. Uphold the law.'},
]
pyautogui.PAUSE = 0.5
for person in formData:
# Give the user a chance to kill the script.
print('>>> 5 SECOND PAUSE TO LET USER PRESS CTRL-C <<<')
time.sleep(5)
# Wait until the form page has loaded.
while not pyautogui.pixelMatchesColor(submitButton[0], submitButton[1], submitButtonColor):
time.sleep(0.5)
print('Entering %s info...' % (person['name']))
pyautogui.click(nameField[0], nameField[1])
# Fill out the Name field.
pyautogui.typewrite(person['name'] + '\t')
# Fill out the Greatest Fear(s) field.
pyautogui.typewrite(person['fear'] + '\t')
# Fill out the Source of Wizard Powers field.
if person['source'] == 'wand':
pyautogui.typewrite(['down', '\t'])
elif person['source'] == 'amulet':
pyautogui.typewrite(['down', 'down', '\t'])
elif person['source'] == 'crystal ball':
pyautogui.typewrite(['down', 'down', 'down', '\t'])
elif person['source'] == 'money':
pyautogui.typewrite(['down', 'down', 'down', 'down', '\t'])
# Fill out the Robocop field.
if person['robocop'] == 1:
pyautogui.typewrite([' ', '\t'])
elif person['robocop'] == 2:
pyautogui.typewrite(['right', '\t'])
elif person['robocop'] == 3:
pyautogui.typewrite(['right', 'right', '\t'])
elif person['robocop'] == 4:
pyautogui.typewrite(['right', 'right', 'right', '\t'])
elif person['robocop'] == 5:
pyautogui.typewrite(['right', 'right', 'right', 'right', '\t'])
# Fill out the Additional comments field.
pyautogui.typewrite(person['comments'] + '\t')
# Click Submit.
pyautogui.press('enter')
# Wait until form page has loaded.
print('Clicked Submit.')
time.sleep(5)
# Click the Submit another response link.
pyautogui.click(submitAnotherLink[0], submitAnotherLink[1])