728x90
반응형
Python selenium을 이용하여 웹 크롤링을 하면 다음 에러가 발생할 수 있다.
에러 발생 코드
next_btn = driver.find_element(By.XPATH, '//*[@id="btnNextPage"]')
next_btn.click() # 작동 하지 않음
selenium.common.exceptions.ElementClickInterceptedException
이 에러는 특정 HTML element를 클릭할 때 해당 element를 클릭할 수 없도록 JS 처리(버튼 클릭 비활성화)가 되어 있거나, selenium과 같은 장치로부터 요소 클릭이 차단된 경우에 발생할 수 있다.
즉 원하는 요소가 다른 요소에 의해 차단 되어 요소를 클릭할 수 없기 때문에 에러가 발생한 것이다.
해결 방법
아래 코드와 같이 JS 코드로 버튼 클릭을 실행하여 해결할 수 있다.
button = driver.find_element_by_xpath("xpath")
driver.execute_script("arguments[0].click();", button)
Reference
반응형
'Programming Language > [Python]' 카테고리의 다른 글
[Python] ModuleNotFoundError (0) | 2024.07.08 |
---|---|
[Python] pytimekr 패키지 (0) | 2024.03.22 |
[Python] ValueError: If using all scalar values, you must pass an index (0) | 2023.11.10 |
[Python] UUID로 고유 식별자 만들기 (0) | 2023.09.15 |
[Python] pandas dataframe 행/열 count (0) | 2023.07.12 |