-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkday_time_sheet.py
More file actions
executable file
·134 lines (115 loc) · 4.07 KB
/
workday_time_sheet.py
File metadata and controls
executable file
·134 lines (115 loc) · 4.07 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/home/asyuksek/anaconda3/bin/python3
from selenium import webdriver
from selenium.common import exceptions
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import yaml
import os
from selenium.webdriver.chrome.service import Service
import pickle
WORKDAY_LINK = "https://wd5.myworkday.com/wday/authgwy/brandeis/login.htmld"
PATH_TO_YAML_FILES = "/home/asyuksek/Brandeis_Undergrad/guru/automation"
HOURS_FILE = "hours.yaml"
def time_sheet():
opt = Options()
opt.add_argument(r"user-data-dir=/home/asyuksek")
driver = webdriver.Chrome(options=opt)
driver.get(WORKDAY_LINK)
time.sleep(5)
driver = log_in(driver)
driver = naivgate_to_to_time(driver)
time.sleep(5)
job_file = open(os.path.join(PATH_TO_YAML_FILES, HOURS_FILE))
job_hours = yaml.load(job_file, Loader=yaml.FullLoader)
for job_name, days_hours in job_hours.items():
for day, hours in days_hours.items():
driver = navigate_to_menu(driver, job_name)
driver = enter_time(driver, day, hours)
job_file.close()
time.sleep(10)
print("Success")
def log_in(driver):
username = driver.find_element(By.XPATH, "//*[@id='username']")
passphrase_enter = driver.find_element(By.XPATH, "//*[@id='password']")
a_yaml_file = open(os.path.join(PATH_TO_YAML_FILES,"credentials.yaml" ))
parsed_yaml_file = yaml.load(a_yaml_file, Loader=yaml.FullLoader)
username.send_keys(parsed_yaml_file["login"]["username"])
passphrase_enter.send_keys(parsed_yaml_file["login"]["password"])
driver.find_element(
By.XPATH, "/html/body/div[1]/div[3]/div/form/div[6]/button"
).click()
a_yaml_file.close()
time.sleep(2)
WebDriverWait(driver, 40).until(EC.title_contains("Home"))
time.sleep(2)
return driver
def naivgate_to_to_time(driver):
time.sleep(5)
navigation = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
(By.XPATH, '//button[@data-automation-id="globalNavButton"]')
)
)
navigation.click()
time.sleep(5)
shortcut = WebDriverWait(driver,10).until(
EC.presence_of_element_located(
(By.XPATH, '//button[@data-automation-id="globalNavShortcutsTab"]')
)
)
shortcut.click()
time_entry = WebDriverWait(driver,10).until(
EC.presence_of_element_located(
(By.XPATH, '//div[@data-automation-id="globalNavShortcutItemLabel"]')
)
)
time_entry.click()
time.sleep(5)
return driver
def navigate_to_menu(driver, job_name):
action = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, '//button[@title="Actions"]'))
)
action.click()
time.sleep(15)
day = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable(
(By.XPATH, '//div[@data-automation-label="Quick Add"]')
)
)
day.click()
time.sleep(5)
show_all = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable(
(By.XPATH, '//div[@data-automation-id="selectShowAll"]')
)
)
show_all.click()
time.sleep(5)
guru = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable(
(By.XPATH, f'//div[@title="{job_name}"]')
)
)
guru.click()
time.sleep(2)
driver.find_element(By.XPATH, '//button[@title="Next"]').click()
time.sleep(5)
return driver
def enter_time(driver, day, hours):
time.sleep(2)
driver.find_element(By.XPATH, f'//div[@data-automation-id="checkbox" and @data-uxi-form-item-child-list-index="{day}"]').click()
time.sleep(5)
start, end = driver.find_elements(
By.XPATH, '//div[@data-automation-id="standaloneTimeWidget"]/input'
)
start.send_keys(hours["start"])
end.send_keys(hours["end"])
time.sleep(5)
driver.find_element(By.XPATH, '//button[@title="OK"]').click()
return driver
time_sheet()