以師大選課系統為例
from selenium import webdriver
from time import sleep
import selenium.webdriver.support.ui as ui
browser = webdriver.Chrome()
browser.maximize_window()
wait = ui.WebDriverWait(browser, 10)
browser.get("http://cos2.ntnu.edu.tw/AasEnrollStudent/LoginCheckCtrl?language=TW")
browser.find_element_by_id("userid-inputEl").send_keys('your admin')
browser.find_element_by_id("password-inputEl").send_keys('your passw')
class_name
tag_name
name
link_text
partial_link_text
css_selector
by_xpath
無障礙輸入,程式操作無障礙
wait.until(lambda browser: browser.find_element_by_id("messagebox-1001-displayfield-inputEl").is_displayed())
check_text = browser.find_element_by_id("messagebox-1001-displayfield-inputEl").text
browser.find_element_by_id("button-1005-btnIconEl").click()
browser.find_element_by_id("validateCode-inputEl").send_keys(check_text)
browser.find_element_by_id("button-1016-btnIconEl").click()
wait.until(lambda browser: browser.find_element_by_id("button-1017-btnIconEl").is_displayed())
browser.find_element_by_id("button-1017-btnIconEl").click()
wait.until(lambda browser: browser.find_element_by_id("now").is_displayed())
這個要低調
browser.execute_script("countSecond = Infinity;")
這個很重要
browser.close()