본문 바로가기

Programming Language/[Python]

[Python] selenium.common.exceptions.ElementClickInterceptedException

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

https://stackoverflow.com/questions/57741875/selenium-common-exceptions-elementclickinterceptedexception-message-element-cl

 

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable with S

I am currently working on a project which fills a form automatically. And the next button appears when the form is filled, that's why it gives me an error. I have tried: WebDriverWait(driver, 10).

stackoverflow.com

반응형