diff --git a/lotto-runner/lotto_auto_buy.py b/lotto-runner/lotto_auto_buy.py index b35c382..364e0e6 100644 --- a/lotto-runner/lotto_auto_buy.py +++ b/lotto-runner/lotto_auto_buy.py @@ -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: + """ +
가 떠 있으면 + 내부 '확인' 버튼을 클릭(= 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")) )