This repository has been archived by the owner on May 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timesheet.py
executable file
·63 lines (52 loc) · 2.44 KB
/
timesheet.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
from time import sleep
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.wait import WebDriverWait
days = ["mon", "tue", "wed", "thu", "fri"]
def fill_timesheet(webdriver, project_id, project_task, is_billable=True) -> None:
try:
wait = WebDriverWait(webdriver, 10)
sleep(2)
workdays = [day for day in days if float(webdriver.find_element_by_xpath(
"//a[@href='#" + day + "']").find_elements_by_tag_name("small")[-1].text) == 0]
for day in workdays:
webdriver.find_element_by_xpath("//a[@href='#" + day + "']").click()
webdriver.find_element_by_xpath(
"//i[@class='fa fa-plus text-light']").find_element_by_xpath('..').click()
wait.until(lambda x: x.find_element_by_id(
"newTimeModal").is_displayed())
project_select_el = wait.until(lambda x: x.find_element_by_xpath(
"//label[contains(text(), 'Project Name')]/following-sibling::select"))
project_select = Select(
project_select_el).select_by_value(project_id)
Select(wait.until(lambda x: x.find_element_by_xpath(
"//label[contains(text(), 'Task Name')]/following-sibling::select"))).select_by_value('0')
Select(webdriver.find_element_by_xpath(
"//label[contains(text(), 'Work Location')]/following-sibling::select")).select_by_value('WFH')
wait.until(lambda x: x.find_element_by_xpath(
"//label[contains(text(), 'End')]/following-sibling::input")).click()
sleep(1)
wait.until(lambda x: x.find_element_by_xpath(
"//button[@aria-label='Minus a hour']")).click()
sleep(1)
wait.until(lambda x: x.find_element_by_xpath(
"//span[contains(text(), 'Set')]")).find_element_by_xpath('..').click()
webdriver.find_element_by_xpath(
"//button[contains(text(), 'Add')]").click()
except Exception:
print("exception")
def submit_timesheet(webdriver) -> None:
wait = WebDriverWait(webdriver, 10)
submit_button = wait.until(lambda x: x.find_element_by_xpath("//button[contains(text(), 'Submit')]"))
webdriver.execute_script("arguments[0].scrollIntoView();", submit_button)
webdriver.execute_script("arguments[0].click();", submit_button)
webdriver.switch_to.alert.accept()
def get_timesheet_date_range(webdriver) -> str:
try:
date_range: WebElement = WebDriverWait(webdriver, 30).until(
lambda x: x.find_element_by_class_name("dtnWeek")
)
return date_range.text
except Exception:
return "?"