def book_ticket(self, standard_seat, i):

# standard_seat는 일반석 검색 결과 텍스트


if "예약하기" in standard_seat:

print("예약 가능 클릭")


# Error handling in case that click does not work

try:

self.driver.find_element(By.CSS_SELECTOR,

f"#result-form > fieldset > div.tbl_wrap.th_thead > table > tbody > tr:nth-child({i}) > td:nth-child(7) > a").click()

except ElementClickInterceptedException as err:

print(err)

self.driver.find_element(By.CSS_SELECTOR,

f"#result-form > fieldset > div.tbl_wrap.th_thead > table > tbody > tr:nth-child({i}) > td:nth-child(7) > a").send_keys(

Keys.ENTER)

finally:

self.driver.implicitly_wait(10)


# 예약이 성공하면

if self.driver.find_elements(By.ID, 'isFalseGotoMain'):

self.is_booked = True

print("예약 성공")

import telegram

bot = telegram.Bot(token='??????????')

chat_id = ??


asyncio.run(bot.send_message(chat_id=chat_id, text="예약성공"))


# bot = telegram.Bot(token='???????')

# chat_id = ???????

# bot.sendMessage(chat_id=chat_id, text="예약성공")


return self.driver

else:

print("잔여석 없음. 다시 검색")

self.driver.back() # 뒤로가기

self.driver.implicitly_wait(5)






1. 기차 예매 코드인데 하늘색으로 친 게 SRT에서 '예약하기' 버튼을 누르는 코드임


기존에는 작동이 잘 됐는데, 지금은 요런 알림창이 뜬단 말임







2. 연두색으로 친 Enter 입력 코드 덕분에 예매까지 는 넘어가지는데


이런 알림창이 뜨는 경우에 대처하는 게 엔터키 치는 것뿐이라 아래와 같은 에러가 뜨면서 텔레그램으로 예약완료 됐다는 메시지를 전송하는 게 안 됨



raise exception_class(message, screen, stacktrace, alert_text)

selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: 선택하신 열차는 SRT 2개 편성을 연결하여 운행하는 열차로서, 반드시 열차번호와 해당호차를 확인하시고 승차하시기 바랍니다.

Message: unexpected alert open: {Alert text : 선택하신 열차는 SRT 2개 편성을 연결하여 운행하는 열차로서, 반드시 열차번호와 해당호차를 확인하시고 승차하시기 바랍니다.}

(Session info: chrome=118.0.5993.70)




3. 그래서 하늘색 친 부분 끝나고 알림창이 뜨면 확인해서 끄는 코드가 필요할 거 같은데 어떻게 하는지 감이 잡히지 않음



도와주면 치킨 기프티콘 사드림...