Helpdesk 的工做愈來愈難作了,作好服務還不夠,受理工單還不能超時。 上面有要求,下面只能出對策了。還好實現起來簡單。web
from selenium import webdriver
from selenium.webdriver.support.select import Select
import time
from selenium.webdriver.common.action_chains import ActionChains
Uname='XXXX'
Pwd='XXXX'瀏覽器
class Opera_ITSM():jsp
def __init__(self,Uname=Uname,Pwd=Pwd): self.Uname=Uname self.Pwd=Pwd url = 'http://ITSM.XXX.COM/arsys/shared/login.jsp?/arsys/home' self.driver = webdriver.Chrome() self.driver.get(url) def ITSM_Login(self): # time.sleep(5) # 定位到攻略按鈕 print(self.driver) el_Uname=self.driver.find_element_by_xpath('//*[@id="username-id"]') el_Pwd=self.driver.find_element_by_xpath('//*[@id="pwd-id"]') el_submit=self.driver.find_element_by_xpath('//*[@id="login"]') el_Uname.send_keys(self.Uname) print('U') time.sleep(1) el_Pwd.send_keys(self.Pwd) print("P") # 點擊操做,前提是定位到元素 time.sleep(1) el_submit.click() def Take_Ticket(self): try: time.sleep(5) el_closeWindow=self.driver.find_element_by_xpath('//*[text()="已指派"]/..') el_closeWindow.click() check = self.driver.find_element_by_xpath('//*[@id="WIN_1_301428900"]/div[2]/div') check.click() time.sleep(2) el_closeWindow=self.driver.find_element_by_xpath('//*[@id="WIN_2_301542000"]/a') el_closeWindow.click() time.sleep(2) el_closeWindow=self.driver.find_element_by_xpath('//*[text()="受理事件"]') el_closeWindow.click() time.sleep(2) el_closeWindow=self.driver.find_element_by_xpath('//*[@id="WIN_0_616122300"]') el_closeWindow.click() return(True) except Exception as e: print(e,'刷新頁面') self.driver.refresh() return(False)
if name == 'main':
ITSM=Opera_ITSM()
ITSM.ITSM_Login()
while True:
print(time.asctime( time.localtime(time.time()) ))
if ITSM.driver:
res=ITSM.Take_Ticket()
if not res:
ITSM.Take_Ticket()
print('等待300秒')
time.sleep(300)
else:
print('等待20秒')
time.sleep(20)ide