Created
September 11, 2014 15:54
-
-
Save alecxe/b8cad2bd779a92c23a95 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
from selenium import webdriver | |
import time | |
from selenium.webdriver.common.keys import Keys | |
import selenium.webdriver.support.ui as ui | |
from selenium.webdriver.support.select import Select | |
url = "http://calstate-la.bncollege.com/webapp/wcs/stores/servlet/TBWizardView?catalogId=10001&langId=-1&storeId=30556" | |
driver = webdriver.Firefox() | |
driver.get(url) | |
wait = ui.WebDriverWait(driver, 10) | |
# get the first book row | |
book_row = driver.find_element_by_class_name('bookRowContainer') | |
# get the terms section | |
term_select_button = driver.find_element_by_class_name('termHeader') | |
term_select_button.click() | |
time.sleep(1) | |
terms = [option.text for option in book_row.find_elements_by_class_name('termOption')] | |
for index, term in enumerate(terms): | |
term_select_button.click() | |
option = wait.until(lambda driver: driver.find_element_by_xpath('//div[contains(@class, "bookRowContainer")]//li[contains(@class, "termOption")][%s]' % (index + 1))) | |
option.click() | |
# get the departments sections | |
department_column = book_row.find_element_by_class_name('deptColumn') | |
department_input = department_column.find_element_by_class_name('deptSelectInput') | |
department_input.click() | |
time.sleep(1) | |
departments = [option.text for option in department_column.find_elements_by_xpath('//li[@class="result"]/h4')] | |
for index, department in enumerate(departments): | |
department_input.click() | |
time.sleep(1) | |
option = book_row.find_element_by_xpath('//li[contains(@class, "deptColumn")]//li[@class="result"][%s]' % (index + 1)) | |
option.click() | |
# clear the field (using clear() doesn't help here - using backspaces) | |
department_input.click() | |
for _ in department: | |
department_input.send_keys(Keys.BACK_SPACE) | |
time.sleep(1) | |
print term, department | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment