feat: 레이어 알림 처리 기능 추가

- 구매 직전에 나타나는 레이어 알림을 감지하고 자동으로 닫는 기능 구현
- close_layer_alert_if_present 함수 추가하여 알림 처리 로직 포함
This commit is contained in:
hyeonggil
2026-03-27 23:21:42 +09:00
parent 65ebf180e9
commit ed73e39b69

View File

@@ -163,6 +163,50 @@ def buy_lotto(driver, game_count=5):
try:
wait = WebDriverWait(driver, 10)
def close_layer_alert_if_present(timeout_s: float = 1.5) -> bool:
"""
<div class="layer-alert" id="popupLayerAlert"> 가 떠 있으면
내부 '확인' 버튼을 클릭(= closepopupLayerAlert())해서 닫는다.
"""
from selenium.common.exceptions import TimeoutException, WebDriverException
try:
layer = WebDriverWait(driver, timeout_s).until(
EC.presence_of_element_located((By.ID, "popupLayerAlert"))
)
except TimeoutException:
return False
try:
if not layer.is_displayed():
return False
except WebDriverException:
# stale 등 예외면 "없음"으로 간주
return False
# 우선 버튼 클릭 시도 (DOM: #popupLayerAlert .btns input[value='확인'])
try:
btn = driver.find_element(
By.CSS_SELECTOR,
"#popupLayerAlert .btns input[type='button'][value='확인']",
)
if btn.is_displayed() and btn.is_enabled():
btn.click()
time.sleep(0.3)
return True
except Exception:
pass
# fallback: 사이트의 close 함수 직접 호출
try:
driver.execute_script(
"if (typeof closepopupLayerAlert === 'function') { closepopupLayerAlert(); }"
)
time.sleep(0.3)
return True
except Exception:
return False
# 모든 레이어 팝업을 JS로 직접 숨기기 (z-index 오버레이 완전 제거)
driver.execute_script("""
var popups = document.querySelectorAll(
@@ -201,6 +245,10 @@ def buy_lotto(driver, game_count=5):
pass
# "구매하기" 버튼 클릭
# 구매 직전에 레이어 알림이 뜨는 경우 먼저 닫기
if close_layer_alert_if_present():
logger.info("구매 전 popupLayerAlert 감지 — 닫기 처리 완료")
buy_btn = wait.until(
EC.element_to_be_clickable((By.ID, "btnBuy"))
)