以登录麦子学院为例
url = 'http://www.maiziedu.com/' link_text = '登录' account = '[email protected]' pwd = 'abc123456' def waituntil_load(driver,times,func): return WebDriverWait(driver,times).until(func) def login_test(): driver = webdriver.Chrome() driver.get(url) #driver.maximize_window() # driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[3]/div/div').click() #关闭弹窗 a = waituntil_load(driver,15,lambda driver:driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[3]/div/div')) a.click() driver.find_element_by_link_text(link_text).click() #点击登录 time.sleep(2) input_zhanghao = driver.find_element_by_id('id_account_l') input_zhanghao.clear() input_zhanghao.send_keys(account) input_pwd = driver.find_element_by_id('id_password_l') input_pwd.clear() input_pwd.send_keys(pwd) driver.find_element_by_id('login_btn').click() time.sleep(10) if __name__ == '__main__': login_test()