-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeleniumTest.py
131 lines (103 loc) · 5.01 KB
/
SeleniumTest.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
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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import glob
import os
import time
from ConvertCSVtoExcel import *
def PyDriveAuthentication(gauth):
# Load the saved client credentials from the file
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
# Authenticate if file is nto found
gauth.GetFlow()
gauth.flow.params.update({'access_type': 'offline'})
gauth.flow.params.update({'approval_prompt': 'force'})
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh authentication if expired
gauth.Refresh()
else:
# Initialize the saved credentials
gauth.Authorize()
# Save credentials to file
gauth.SaveCredentialsFile("mycreds.txt")
def SendToGoogleDrive(FolderID, drive):
GoogleSheetFile = ""
# If the CSVFile contains only 1 file, then execute this command
if len(os.listdir(os.path.dirname(__file__) + "\CSVFile")) == 1:
for file in glob.glob('CSVFile/*.csv'):
GoogleSheetFile = file
# If the CSV contains more than 1 file, retrieve the most recent file
else:
GoogleSheetFile = max(glob.iglob('CSVFile/*.csv'), key=os.path.getctime)
GoogleSheetFile = CSVtoExcel(GoogleSheetFile)
time.sleep(3)
file1 = drive.CreateFile({"parents": [{"kind": "drive#fileLink", "id": FolderID}]})
file1.SetContentFile(GoogleSheetFile)
file1.Upload()
# The main Selenium script that requires user's inputted username & password to run
def SeleniumScript(username1, password2):
# Calling the Google Drive Authentication function
gauth = GoogleAuth()
PyDriveAuthentication(gauth)
# Adjusting the options of the ChromeDriver
chromeOptions = Options()
chromeOptions.add_experimental_option("prefs",
{"download.default_directory": os.path.dirname(__file__) + "\CSVFile",
"safebrowsing.enabled": "false"})
driver = webdriver.Chrome(executable_path='Driver/chromedriver.exe', options=chromeOptions)
driver.get('https://rutgers.zoom.us/')
driver.find_element_by_link_text("#").click()
username = driver.find_element_by_id("username")
username.clear()
username.send_keys("", username1)
password = driver.find_element_by_name("password")
password.clear()
password.send_keys("", password2)
driver.find_element_by_class_name('btn-submit').click()
driver.find_element_by_css_selector("a[href='https://rutgers.zoom.us/account/report']").click()
driver.find_element_by_css_selector("a[href='https://rutgers.zoom.us/account/my/report']").click()
driver.find_element_by_xpath('//*[@id="searchMyForm"]/div/button[1]/img').click()
driver.find_element_by_xpath('//*[@id="searchMyForm"]/div/button[2]/img').click()
day = driver.find_element_by_xpath( "//*[@id='ui-datepicker-div']/table/tbody/tr/td[contains(@class,' ui-datepicker-days-cell-over ui-datepicker-current-day ui-datepicker-today')]").text
day = int(day)
driver.find_element_by_xpath('//*[@id="searchMyForm"]/div/button[1]/img').click()
# If the day in the calendar web app is more than 7, execute this script
if day > 7:
newday = day - 7
newday = str(newday)
Command1 = "//*[@id='ui-datepicker-div']/table/tbody/tr/td/a[contains(text(),'"
Command2 = "')]"
FullCommand = Command1 + newday + Command2
driver.find_element_by_xpath(FullCommand).click()
# If the day in the calendar web app is less than 7, change the calendar to the previous month and execute this
# script
else:
driver.find_element_by_xpath('//*[@id="ui-datepicker-div"]/div[1]/a[1]').click()
newdate = 20 + day
newdate = str(newdate)
Command1 = "//*[@id='ui-datepicker-div']/table/tbody/tr/td/a[contains(text(),'"
Command2 = "')]"
FullCommand = Command1 + newdate + Command2
driver.find_element_by_xpath(FullCommand).click()
# Clicks the Search button
driver.find_element_by_id("searchMyButton").click()
# Find and select the last item in that list
driver.find_element_by_xpath('//*[@id="meeting_list"]/tbody/tr[last()]/td[12]/a').click()
# Wait a few seconds
driver.implicitly_wait(10)
# Click unique users (if available)
VerifyUniqueUsers = driver.find_element_by_xpath('//*[@id="selectUniqueDiv"][contains(@style,"display: none;")]')
if VerifyUniqueUsers:
pass
else:
driver.find_element_by_xpath('//*[@id="selectUniqueDiv"][contains(@style,"display: block;")]').click()
driver.find_element_by_xpath('//*[@id="withMeetingHeader"]').click()
# Find the button to export the attendance sheet and download it
driver.find_element_by_xpath("//*[@id='btnExportParticipants']").click()
drive = GoogleDrive(gauth)
FolderID = '1xSP296-9AyZ32QONx4zfpv0ScDNOHKAW'
time.sleep(5)
SendToGoogleDrive(FolderID, drive)