Last active
December 29, 2019 14:35
-
-
Save shivankgtm/cf6fb3ca80fee068a3f82284445a507b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from selenium import webdriver | |
import pandas as pd | |
# from webdriver_manager.chrome import ChromeDriverManager # Only required in Linux | |
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 | |
data = pd.read_excel(r'form1.xlsx') | |
for i in range(len(data)): | |
driver = webdriver.Chrome(ChromeDriverManager().install()) # Linux | |
# driver = webdriver.Chrome(executable_path = '') # Windows | |
driver.get('https://testservices.nic.in/examsys/root/AuthForAdmitCardDwd.aspx?enc=Ei4cajBkK1gZSfgr53ImFQTbjVzuZ1mQajFt6EnKeZEk28J/HZOEuCngppd8/JG7') | |
# Registration Number being fetched from from.xlsx. | |
# Same with DOB | |
reg_num = data['JEE(Jan2020) Application Num'][i] | |
driver.find_element_by_name('ctl00$ContentPlaceHolder1$txtRegno').send_keys(str(reg_num)) | |
DOB = str(data['DOB(DD/MM/YYYY)'][i]) | |
DOB = DOB[:10].split('-') | |
# DOB - Date | |
date = driver.find_element_by_name('ctl00$ContentPlaceHolder1$ddlday') | |
date.send_keys(DOB[2]) | |
# DOB-Month | |
month = driver.find_element_by_name('ctl00$ContentPlaceHolder1$ddlmonth') | |
month.send_keys(DOB[1]) | |
# DOB-Year | |
year = driver.find_element_by_name('ctl00$ContentPlaceHolder1$ddlyear') | |
year.send_keys(DOB[0]) | |
#CAPTCHA | |
driver.find_element_by_name('ctl00$ContentPlaceHolder1$txtsecpin').send_keys('T6GH') | |
driver.find_element_by_name('ctl00$ContentPlaceHolder1$btnsignin').click() | |
try: | |
# line waiting for Admit card link to be find. | |
# If pdf link does not find for 15 seconds it will be TimeOut. | |
myElem = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.ID, 'ctl00_LoginContent_lnkAdmitCard'))) | |
z = driver.find_elements_by_id('ctl00_LoginContent_lnkAdmitCard') | |
z[0].click() | |
print(reg_num) | |
time.sleep(2) | |
driver.quit() | |
# TimeOut can be of two reasons. | |
# 1. Either the page is still loading. | |
# 2. or Invalid registration number or captcha. | |
except TimeoutException: | |
try: | |
# Following line will confirm if Reg_Num/DOB is invalid. | |
myElem = WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.ID, 'ctl00_ContentPlaceHolder1_lblerror1'))) | |
print('Reg_Num or DOB is wrong', reg_num) | |
# invalid_regis.txt is a file which will tackle invalid reg_number. | |
invalid_reg_dob = open('invalid_regis.txt', 'a') | |
invalid_reg_dob.write(str(reg_num)+'\n') | |
invalid_reg_dob.close() | |
driver.quit() | |
except TimeoutException: | |
print('Taking two long') | |
driver.quit() | |
#except: | |
# print('Taking too long') | |
# driver.quit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment