-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
174 lines (153 loc) · 7.62 KB
/
bot.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from tkinter import *
from tkinter.ttk import *
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import os
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
import pandas as pd
def runbot(entries):
import time
#s1 = pd.read_excel('person_details.xlsx', 'Sheet1')
#Defining browser
#browser = webdriver.Chrome(str(os.getcwd()) + "/chromedriver")
browser: WebDriver = webdriver.Firefox(executable_path ='geckodriver')
browser.get('https://sso.rajasthan.gov.in/signin')
browser.implicitly_wait(15)
# Input form ------
# First form --------
browser.find_element_by_xpath('//*[@id="cpBody_txt_Data1"]').send_keys('DAILYTOUR360')
browser.find_element_by_xpath('//*[@id="cpBody_txt_Data2"]').send_keys('DTT4SHALU')
input('Press enter after solving captcha')
'''//*[@id="bt_login"]/i'''
# Close pop up
try:
browser.find_element_by_xpath('//*[@id="cpBody_btn_LDAPLogin"]').click()
except:
print('no pop up was found')
# Second form ------
#element = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, "cpBody_dlApplications_LinkButton2_0")))
browser.implicitly_wait(10)
try:
browser.find_element_by_xpath('//*[@id="cpBody_txt_Data2"]').send_keys('DTT4SHALU')
time.sleep(1)
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, 'cpBody_cbx_newsession'))).click()
browser.find_element_by_xpath('.//*[@id="cpBody_btn_LDAPLogin"]').click()
except:
time.sleep(1)
browser.implicitly_wait(10)
#element = WebDriverWait(browser, 10).until_not(EC.visibility_((By.ID, "cpBody_dlApplications_LinkButton2_0")))
element = browser.find_element_by_id("cpBody_dlApplications_LinkButton2_0")
browser.execute_script("arguments[0].click();", element)
browser.implicitly_wait(10)
elem = browser.find_elements_by_class_name("fa.fa-ticket.fa-fw")
browser.execute_script('arguments[0].click();', elem[0])
browser.implicitly_wait(3)
elem = browser.find_element_by_xpath('//a[@href="/BookOnlineTicket/BookOnlineTicket?CT=QWR2YW5jZQ=="]')
browser.execute_script('arguments[0].click();', elem)
'''while True:
try:
#WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, "fa.fa-ticket.fa-fw"))).click()
#WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, "//a[@href='/BookOnlineTicket/BookOnlineTicket?CT=QWR2YW5jZQ==']"))).click()
elem = browser.find_elements_by_class_name("fa.fa-ticket.fa-fw")
elem[0].click()
browser.implicitly_wait(1)
#WebDriverWait(browser, 10).until(EC.presence_of_element_located(
# (By.XPATH, "//a[@href='/BookOnlineTicket/BookOnlineTicket?CT=QWR2YW5jZQ==']"))).click()
browser.find_element_by_xpath('//a[@href="/BookOnlineTicket/BookOnlineTicket?CT=QWR2YW5jZQ=="]').click()
break
except:
time.sleep(2)'''
try:
browser.implicitly_wait(4)
buttons = browser.find_elements_by_class_name("close")
buttons[1].click()
except:
pass
number_of_seats = None
while True:
text = browser.find_element_by_xpath('//*[@id="lbl_NumberofMembersavailable"]').text
if text != '':
print(text)
number_of_seats = int(text.split(': ')[1])
print(number_of_seats)
break
time.sleep(2)
#if number_of_seats > s1['Name'].count():
if number_of_seats > len(entries):
table_id = browser.find_element_by_id('tblMemberInfo')
rows = table_id.find_elements(By.XPATH, ".//*[contains(@id,'tbdMemberInfo')]") # get all of the rows in the table
k = 0
print("number of rows found ", len(rows))
numberOfMembers = len(entries)
print("number of records to enter ", numberOfMembers)
maxK = numberOfMembers
option_values = {
"Passport":'1',
"Aadhar":'2',
"Driving Licence":'3',
"Voter ID":'4',
"PAN Card":'5',
"Office ID":'6',
"Student ID":'7'
}
for j in range(numberOfMembers):
if entries[j][2].get() != '--select--' and entries[j][2].get() != '--select--' and entries[j][3].get() != '--select--':
for i in range(6):
print(entries[j][i].get())
browser.implicitly_wait(5)
# name
label = 'Member' + 'Name' + str(j)
element = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, label)))
#element.clear()
element.send_keys(entries[j][0].get())
element.send_keys(Keys.TAB)
time.sleep(0.25)
#blockUI blockMsg blockPage
# gender
label = 'Member' + 'Gender' + str(j)
element = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, label)))
element.send_keys(str(entries[j][1].get()))
element.send_keys(Keys.TAB)
time.sleep(0.25)
# nationality
label = 'Member' + 'Nationality' + str(j)
element = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, label)))
element.send_keys(str(entries[j][2].get()))
element.send_keys(Keys.TAB)
time.sleep(1)
# ID type
label = 'Member' + 'IdType' + str(j)
element = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, label)))
hov0 = ActionChains(browser).move_to_element(element)
hov0.perform()
if str(entries[j][2].get()) == 'Foreigner':
browser.find_element_by_xpath("//select[@id='" + label + "']/option[@value='1']").click()
else:
browser.find_element_by_xpath("//select[@id='"+label+"']/option[@value='" + option_values[str(entries[j][3].get())] + "']").click()
#Select(browser.find_element_by_css_selector("select#" + label)).select_by_visible_text(str(entries[j][3].get())).click()
#element.send_keys(str(entries[j][3].get()))
#element.send_keys(Keys.TAB)
time.sleep(0.25)
# ID No,
label = 'Member' + 'IdNo' + str(j)
element = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, label)))
element.send_keys(str(entries[j][4].get()))
element.send_keys(Keys.TAB)
time.sleep(1)
# Video camera
label = 'MemberTotalCamera' + str(j)
# element = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, label)))
element = browser.find_element_by_id(label)
hov = ActionChains(browser).move_to_element(element)
hov.perform()
element.send_keys(str(entries[j][5].get()))
element.send_keys(Keys.TAB)
time.sleep(2)
while True:
pass