-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomatedForm.py
More file actions
118 lines (87 loc) · 3.65 KB
/
automatedForm.py
File metadata and controls
118 lines (87 loc) · 3.65 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/local/bin/python3
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import json
import os
#import pyvirtualdisplay
#from pyvirtualdisplay import Display
#from selenium import webdriver
import webdriver_manager
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
import chromedriver_binary
CHROMEDRIVER_PATH='./env/bin/chromedriver'
#options = Options()
#options.headless = True
#browser = webdriver.Chrome(executable_path='/env/bin/chromedriver', chrome_options=options)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("window-size=1024,768")
chrome_options.add_argument("--no-sandbox")
# Initialize a new browser
browser = webdriver.Chrome(chrome_options=chrome_options)
#browser = webdriver.PhantomJS(executable_path=os.getcwd() + '/env/bin/phantomjs')
#browser = webdriver.Chrome(ChromeDriverManager().install())
#browser = webdriver.Chrome()
with open('filePaths.json') as f:
paths = json.load(f)
#with open('testInput.json', encoding='utf-8') as data_file:
# inputs = json.loads(data_file.read())
descriptionPath = '//*[@id="request-description-input"]'
picturePath = "//input[@type='file']"
submitPath = '/html/body/div[2]/div/div[2]/div/div[1]/div[2]/div/form/div[2]/div[9]/button[2]/span[1]'
finalSubmitPath = '/html/body/div[7]/div/div/div[2]/div[1]/form/div[1]/p/a'
#javascript to scroll view
scrollToViewScript = "arguments[0].scrollIntoView(true);"
def start():
browser.get("https://topics.arlingtonva.us/reportproblem/")
time.sleep(1)
frame = browser.find_elements_by_tag_name("iframe")
browser.switch_to.frame(frame[0])
#graffitiButton = browser.find_elements_by_link_text('Graffiti')
#print(graffitiButton)
def navigateToForm(problem):
firstTypeSelect = browser.find_element_by_xpath(paths[problem]['address'])
browser.execute_script(scrollToViewScript, firstTypeSelect)
firstTypeSelect.click()
nextButton = browser.find_element_by_xpath(paths[problem]['next'])
browser.execute_script(scrollToViewScript, nextButton)
nextButton.click()
def fillForm(inputs):
problem = inputs['name']
for key in paths[problem]['inputs'].keys():
if(key!='description' and key!='picture' and key!='latitude' and key!='longitude'):
tmpBox = browser.find_element_by_xpath(paths[problem]['inputs'][key])
browser.execute_script(scrollToViewScript, tmpBox)
tmpBox.send_keys(inputs[key])
else:
if(key=='description' and paths[problem]['inputs'][key]):
descriptionBox = browser.find_element_by_xpath(descriptionPath)
descriptionBox.send_keys(inputs["describe"])
elif(key=='picture' and paths[problem]['inputs'][key]):
picUpload = browser.find_element_by_xpath(picturePath)
picUpload.send_keys(inputs[key])
time.sleep(5)
submitBox = browser.find_element_by_xpath(submitPath)
submitBox.click()
time.sleep(3)
finalSubmit = browser.find_element_by_xpath(finalSubmitPath)
#finalSubmit.click()
#navigateToForm(inputs['name'])
#fillForm(inputs)
#parkBox = browser.find_element_by_xpath(paths["Litter"]['inputs']['park'])
#parkBox.send_keys("Lyons Park")
#finalSubmit.click()
#image upload xpath: '/html/body/div[2]/div/div[2]/div/div[1]/div[2]/div/form/div[2]/div[6]/div/span[1]/input[2]'
""" "Traffic": {
"address": "",
"next": "",
"inputs": {
"location": "",
"street": "",
"type": ""
}
} */ """