selenium_UnexpectedAlertPresentException

Jio.B·2023년 7월 20일
0

오류 해결 

목록 보기
7/10

  • 에러 코드
html = driver.page_source
dom = BeautifulSoup(html, 'html.parser')
contents = dom.select('#placesList li')
len(contents)
  • 원인
    selenium webdriver는 페이지에서 발생하는 알림창을 자동으로 처리하지 못함 = 예상치 못한 알림창 나타날때 자주 발생

  • 해결 방법
    방법 1) 알림창을 닫거나 텍스트를 확인하도록 설정
    방법 2) 예외처리를 통해 프로그램을 매끄럽게 진행시킴

- Alert 핸들링

try:
	wait.until(EC.alert_is_present())
    alert = Alert(driver)
    alert_text = alert.text  # Alert의 내용을 읽어옴
    alert.accept()
    shared_queue.put(f'{alert_text}\n')
    time_sleep()
    driver.switch_to.window(all_window_handles[0])
    driver.switch_to.default_content()  # 프레임 전환
    continue

참고 : https://blog.naver.com/tank100/223127153331

1개의 댓글

comment-user-thumbnail
2023년 7월 20일

잘 봤습니다. 좋은 글 감사합니다.

답글 달기