mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-17 23:13:03 +08:00
345cb95b98
将 findBestTimeOption 中的预约/续约双分支逻辑抽象为策略模式: - TimeOptionReader 负责从 WebElement 提取时间数据(ReserveTimeReader / RenewTimeReader) - TimeDecisionMaker 执行纯决策算法,零 Selenium 依赖 - TimeSelectMaker 作为工厂统一创建配置好的决策器 - 共享常量 LIBRARY_CLOSE_MINS 统一收敛至 TimeSelectMaker 同时将 Overlay 基类重命名为 Dialog,SeatMapOverlay 同步更名为 SeatMapDialog,保持命名一致性。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
100 lines
2.5 KiB
Python
100 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Copyright (c) 2026 KenanZhu.
|
|
All rights reserved.
|
|
|
|
This software is provided "as is", without any warranty of any kind.
|
|
You may use, modify, and distribute this file under the terms of the MIT License.
|
|
See the LICENSE file for details.
|
|
"""
|
|
from selenium.common.exceptions import (
|
|
ElementNotInteractableException,
|
|
NoSuchElementException,
|
|
TimeoutException,
|
|
)
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.remote.webdriver import WebDriver
|
|
from selenium.webdriver.remote.webelement import WebElement
|
|
|
|
from pages.components.Dialog import Dialog
|
|
|
|
|
|
class RenewDialog(Dialog):
|
|
"""
|
|
Renewal time selection dialog.
|
|
"""
|
|
|
|
ROOT = (By.ID, "extendDiv")
|
|
|
|
MESSAGE_HEAD = (By.CSS_SELECTOR, "#extendDiv p.messageHead")
|
|
RESULT_MSG = (By.CSS_SELECTOR, "#extendDiv div.resultMessage")
|
|
TIME_OPTS = (By.CSS_SELECTOR, "#extendDiv .renewal_List li")
|
|
OK_BTN = (By.CSS_SELECTOR, "#extendDiv .btnOK")
|
|
|
|
def __init__(
|
|
self,
|
|
driver: WebDriver,
|
|
) -> None:
|
|
|
|
super().__init__(driver, self.ROOT, auto_close_on_exit=False)
|
|
|
|
def waitUntilReady(
|
|
self,
|
|
) -> bool:
|
|
|
|
try:
|
|
self._waitVisible(self.ROOT)
|
|
self._waitPresence(self.MESSAGE_HEAD)
|
|
self._waitPresence(self.RESULT_MSG)
|
|
except (NoSuchElementException, TimeoutException):
|
|
return False
|
|
except Exception:
|
|
return False
|
|
head_msg = self._find(*self.MESSAGE_HEAD).text.strip()
|
|
if "警告" in head_msg:
|
|
return False
|
|
try:
|
|
self._waitAllPresence(self.TIME_OPTS)
|
|
self._waitPresence(self.OK_BTN)
|
|
except (NoSuchElementException, TimeoutException):
|
|
return False
|
|
except Exception:
|
|
return False
|
|
return True
|
|
|
|
def getHeadMessage(
|
|
self,
|
|
) -> str:
|
|
|
|
return self._find(*self.MESSAGE_HEAD).text.strip()
|
|
|
|
def getResultMessage(
|
|
self,
|
|
) -> str:
|
|
|
|
return self._find(*self.RESULT_MSG).text.strip()
|
|
|
|
def getTimeOptions(
|
|
self,
|
|
) -> list[WebElement]:
|
|
|
|
return self._findAll(*self.TIME_OPTS)
|
|
|
|
def getOkButton(
|
|
self,
|
|
) -> WebElement:
|
|
|
|
return self._find(*self.OK_BTN)
|
|
|
|
def clickOk(
|
|
self,
|
|
) -> bool:
|
|
|
|
try:
|
|
self._find(*self.OK_BTN).click()
|
|
return True
|
|
except (NoSuchElementException, TimeoutException, ElementNotInteractableException):
|
|
return False
|
|
except Exception:
|
|
return False
|