#UTF-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import time
import pyautogui
import schedule
def job():
print("执行复位任务...")
# 创建浏览器驱动,使用Chrome浏览器
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
driver = webdriver.Chrome(options=options)
# 访问指定URL
url = 'https://192.168.28.47'
driver.get(url)
# 等待页面加载完毕
wait = WebDriverWait(driver, 5)
username_input = wait.until(EC.presence_of_element_located((By.NAME, 'username')))
password_input = wait.until(EC.presence_of_element_located((By.NAME, 'password')))
# 输入用户名和密码
username_input.send_keys('admin')
password_input.send_keys('admin')
password_input.send_keys(Keys.ENTER)
pyautogui.press('enter')
# 点击登录按钮
# login_button = wait.until(EC.presence_of_element_located((By.ID, "login")))
# login_button.click()
# 切换到框架
driver.switch_to.frame(0)
page = driver.current_url
print(page)
try:
reset = wait.until(EC.presence_of_element_located((By.ID, "reset1")))
reset.click()
except TimeoutException:
print("Element not found after 10 seconds.")
# 模拟按下回车键
pyautogui.press('enter')
pyautogui.press('enter')
# 关闭浏览器
time.sleep(5)
driver.quit()
# job()
schedule.every(10).minutes.do(job)
while True:
schedule.run_pending()
time.sleep(1)