[text] exercise 7 - selenium

Viewer

copydownloadembedprintName: exercise 7 - selenium
  1. # pyex7_selenium_webadvisor.py - Interact with webadvisor course search
  2.  
  3. from selenium import webdriver
  4. from selenium.webdriver.support.ui import Select        # for dropdown menus
  5. from selenium.webdriver.chrome.options import Options   # for "headless" Chrome
  6. import time                                             # implement pauses
  7.  
  8. # Instance of Options class to configure headless Chrome
  9. options = Options()
  10.  
  11. # Parameter to tell Chrome that it should run without UI (headless)
  12. options.headless = True
  13.  
  14. driver = webdriver.Chrome(options=options)
  15.  
  16. driver.get('https://www2.monmouth.edu/muwebav/wa3/search/SearchClassesv2.aspx')
  17.  
  18. # Select the term
  19. term_val = '23/SU'
  20.  
  21. # Find the Term dropdown menu
  22. term_select = Select(driver.find_element_by_name('_ct10:MainContent:ddlTerm'))
  23. term_select.select_by_value(term_val)
  24.  
  25. # Select the subject
  26. subj_val = 'CS'
  27.  
  28. # Find the Subject dropdown menu
  29. subj_select = Select(driver.find_element_by_name('_ct10:MainContent:ddlSubj_1'))
  30. subj_select.select_by_value(subj_val)
  31.  
  32. # Click the Submit button
  33. driver.find_element_by_name('_ct10:MainContent:btnSubmit').click()
  34.  
  35. # Get resulting html and print it
  36. print(driver.page_source)
  37.  
  38. # Close the browser window
  39. driver.quit 

Editor

You can edit this paste and save as new: