-
Notifications
You must be signed in to change notification settings - Fork 4
/
AeriesSession.py
executable file
·70 lines (61 loc) · 2.47 KB
/
AeriesSession.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
#!/usr/bin/python2
#Selenium allows for scripting a full web browser
# (including graphical ones such as Chrome and Firefox)
# though here, graphics are not wanted and so a headless
# browser is used
#Webdriver is interface to the selected browser (PhantomJS)
from selenium import webdriver
#Ability to select values in HTML <select> tags
from selenium.webdriver.support import select
import time
#Base URL of the AUSDK12 Aeries system
BASE_URL= 'https://abi.ausdk12.org/aeriesportal/'
#Name of the login page (relative to the base URL)
LOGIN_PAGE = 'LoginParent.aspx'
#<form> id, not currently used
#FORM_ID = 'form1'
#id for email <input>
EMAIL_ID = 'portalAccountUsername'
#id for password <input>
PASSWORD_ID = 'portalAccountPassword'
#id for login button
LOGIN_ID = 'LoginButton'
class Session:
#Maintain an instance of a browser, preserving the
# page accross calls
global driver
#Initialize the Session and login in to the Aeries website
# if successful, the browser will be on the home page
# (having been redirected from the login page on submit)
def __init__(self, email, password):
#print "Email: " + str(email)
#print "Password: " + str(password)
login_url = BASE_URL + LOGIN_PAGE
self.driver = webdriver.PhantomJS(service_log_path='/dev/null')
self.driver.get(login_url)
email_elem = self.driver.find_element_by_id(EMAIL_ID)
email_elem.send_keys(email)
password_elem = self.driver.find_element_by_id(PASSWORD_ID)
password_elem.send_keys(password)
login_elem = self.driver.find_element_by_id(LOGIN_ID)
login_elem.click()
if self.driver.current_url == login_url:
raise ValueError('failed to login')
#Execute Javascript on the current page
def executeJS(self, js):
self.driver.execute_script(js)
return self.driver.page_source
#Select a value given the <select> tag's id (elem_id) and the
# option value (option)
def select(self, elem_id, option):
elem = self.driver.find_element_by_id(elem_id)
select_elem = select.Select(elem)
select_elem.select_by_value(option)
#If the page is not already loaded, go to the page; either way,
# return the page
def getPage(self, url):
if self.driver.current_url != url:
self.driver.get(url)
return self.driver.page_source
def getCurrentURL(self):
return self.driver.current_url