自动授课


#导入各种包
from selenium import webdriver#浏览器
from selenium.webdriver.common.by import By#选择器
from selenium.webdriver.support import expected_conditions as EC#等待条件
from selenium.webdriver.support.wait import WebDriverWait#等待
from selenium.webdriver.common.keys import Keys#键盘
from selenium.common.exceptions import NoSuchElementException,StaleElementReferenceException,ElementNotVisibleException,TimeoutException,WebDriverException#各种错误类型
import time#计时器

def login():
	url='https:///login.html'
	global dr
	dr=webdriver.Chrome()
	dr.maximize_window()
	dr.get(url)

	try:
		dr.switch_to.frame('wx-login')
	except:
		print('查找内嵌iframe失败!')
		return

	try:
		em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'div.codelogin-bto>span')))
		em.click()
	except:
		print('单击平台账号密码登录失败!')
		return

	try:
		em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'input[placeholder="请输入平台帐号"]')))
		em.send_keys('')
	except:
		print('输入账号失败!')
		return

	try:
		em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'input[placeholder="请输入平台密码"]')))
		em.send_keys('')
	except:
		print('输入密码失败!')
		return
#class="el-button.el-button--primary"
	try:
		em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'button.el-button.el-button--primary')))
		em.click()
	except:
		print('单击登录失败!')
		return
#p:nth-child(2)
	time.sleep(2)

	try:
		em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,"#teacherEntrance > li:nth-child(4) > a")))
		em.click()
	except:
		print('单击去授课失败!')
		return
	time.sleep(2)

	try:
		dr.switch_to.window(dr.window_handles[len(dr.window_handles)-1])
		#dr.switch_to.window(dr.window_handles[0])
	except:
		print('跳转到新页面失败!')
		return
	time.sleep(2)


	try:
		ems=dr.find_elements(By.CSS_SELECTOR,'a.skbtn')
		print(len(ems))
	except:
		print('单击【去授课】失败!')
		returntime.sleep(2)


	for em in ems:
		try:
			if("display" in em.get_attribute('style'))==False:
				em.click()
				break
		except:
			print('选择未完成授课失败!')
			continue
	time.sleep(3)




	try:
		#em=dr.find_element_by_css_selector('a#OKBtn')
		em=WebDriverWait(dr,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'a#OKBtn')))
		em.click()
	except:
		print('确认授课失败!')
		return
	time.sleep(1)



	try:
		alert1 = dr.switch_to.alert
		# 获取alert窗口的值
		#print(alert1.text)
		# 点击 确定
		if(alert1.text.find('其他时间')):
			alert1.accept()
			print('不在授课时间')
			return
	except:
		print('确定警告失败!')
		return
	print('完成授课!')

if __name__ == '__main__':
	login()

  

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/289385.html

(0)
上一篇 2022年9月14日
下一篇 2022年9月14日

相关推荐

发表回复

登录后才能评论