# encoding=utf-8 from selenium import webdriver # 導入web驅動 import time # 導入時間 # import testCommon.home as comman driver = webdriver.Chrome() def openWebLogin(flag): """ :param flag:0表明建立人,1表明審批人 :return: """ # driver = webdriver.Chrome() driver.get("http://xxxxxxxxxxxxx.com") driver.maximize_window() # 窗口最大化 time.sleep(1) driver.find_element_by_id('loginForm') driver.find_element_by_id('userName').clear() js1 = "var username=document.getElementById(\"userName\");username.style.border=\"2px solid red\";" driver.execute_script(js1) time.sleep(1) if flag == 0: driver.find_element_by_id('userName').send_keys('0260000006') time.sleep(1) driver.find_element_by_id('pwd').clear() js2 = "var pwd = document.getElementById(\"pwd\");pwd.style.border=\"2px solid red\";" driver.execute_script(js2) time.sleep(1) driver.find_element_by_id('pwd').send_keys('1') time.sleep(2) # driver.execute_script('alert("輸入框紅了。")') driver.find_element_by_id('loginForm').submit() if flag == 2: driver.find_element_by_id('userName').send_keys('0096000020') time.sleep(1) driver.find_element_by_id('pwd').clear() js2 = "var pwd = document.getElementById(\"pwd\");pwd.style.border=\"2px solid red\";" driver.execute_script(js2) time.sleep(1) driver.find_element_by_id('pwd').send_keys('1') time.sleep(2) # driver.execute_script('alert("輸入框紅了。")') driver.find_element_by_id('loginForm').submit() driver.implicitly_wait(5) return driver if __name__ == '__main__': openWebLogin()