공부일지

[Python]selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable 본문

Computer/공부정리

[Python]selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

이르리의 공부일지 2023. 10. 16. 11:55

크롤러에 element 연결이 안 된다는 오류가 있었다.

 

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

 

해결한 줄 알았는데 해결이 안 됐다.

 

그래서 다음과 같은 시도 끝에 문제를 해결했다.

 

 

1. 크롬 및 크롬 드라이버 업뎃

 

2. .click() → .send_keys()

 

3. .send_keys() → .execute_script() >>해결!

 

 

 


처음 오류

Traceback (most recent call last):
  File "/Users/yeolmaecompany/Desktop/auction_solution_crawler/crawler.py", line 64, in <module>
    df, kinds = auc.main(driver, df)
                ^^^^^^^^^^^^^^^^^^^^
  File "/Users/yeolmaecompany/Desktop/auction_solution_crawler/auction/SeoulAuction.py", line 442, in main
    driver.find_element_by_xpath("//*[@class='utility-login']").click()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 693, in _execute
    return self._parent.execute(command, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 418, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=117.0.5938.149)

 

 

크롬 드라이버도 업뎃하고 .click()에서 .send_keys()로 바꾼 뒤에도 뜬 오류

Traceback (most recent call last):
  File "/Users/yeolmaecompany/Desktop/auction_solution_crawler/crawler.py", line 64, in <module>
    df, kinds = auc.main(driver, df)
                ^^^^^^^^^^^^^^^^^^^^
  File "/Users/yeolmaecompany/Desktop/auction_solution_crawler/auction/SeoulAuction.py", line 449, in main
    driver.find_element_by_xpath("//*[@class='utility-login']").send_keys(Keys.ENTER)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 539, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT,
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 693, in _execute
    return self._parent.execute(command, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 418, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=118.0.5993.70)

 

 

 

 


해결방법

login = driver.find_element_by_xpath("//*[@class='utility-login']/a[1]")
driver.execute_script("arguments[0].click();", login)
# driver.find_element_by_xpath("//*[@class='utility-login']/a[1]").send_keys(Keys.ENTER)
# driver.find_element_by_xpath("//*[@class='utility-login']").click()

 

주석처럼


여러번의 시도 끝에 해결했다.

 

 


참고 블로그들

1) 코드 수정 

 

최종 시도: .execute_script() 이용

 

https://stackoverflow.com/questions/56194094/how-to-fix-this-issue-element-not-interactable-selenium-python

 

How to fix this issue element not interactable Selenium Python

I have the following line in my script code, where the XPath I got it from Selenium IDE that works fine: driver.find_element_by_xpath("(//a[contains(@href, '')])[20]").click() An automation test ...

stackoverflow.com

 

위 방법으로 적용해서 최종적으로 해결했다!

해당 코드는 아래와 같다.

(다른 방법은 왜 안 됐는지 잘 모르겠다.)

login = driver.find_element_by_xpath("//*[@class='utility-login']/a[1]")
driver.execute_script("arguments[0].click();", login)

 

 

시도: .send_keys() 이용

 

https://letsstudylog.tistory.com/89

 

[Python]selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable 크롤러에서 발생한 오류이다. .click() → .send_keys(Keys.ENTER) 하면 해결되는 오류이다. .send_keys를 쓰려면 아래와 같이 import 해

letsstudylog.tistory.com

 

내 블로그에 써놨음.

예전에 같은 에러일 때 해결했었는데 이번에는 안 됐다.

driver.find_element_by_xpath("//*[@class='utility-login']/a[1]").send_keys(Keys.ENTER)

 

 

 

 

2) 맨 처음 시도: Chrome 업뎃 및 chromedriver 새로 설치

 

https://letsstudylog.tistory.com/73

 

[Selenium]크롬 버전 확인 및 크롬 드라이버 설치

크롬 버전 확인하기 ▼ 크롬-크롬 맞춤설정 및 제어(우측 상단 점 세개 버튼)-설정-Chrome 정보 혹은 url 창에 chrome://version/ 쳐서 확인 크롬 드라이버 설치 ▼ ~114 버전 https://chromedriver.chromium.org/downlo

letsstudylog.tistory.com

 

처음에 오류를 보고

 

크롬 드라이버 버전 문제인가 싶어서 새로 다운로드해서 프로젝트 폴더에 집어넣었다.

 

그랬더니, 

 

'개발자를 확인할 수 없기 때문에 'chromedriver'을(를) 열 수 없습니다.' 라는 안내문구가 떴다.

 

아래는 해당 오류 해결 하기 위해 참고한 블로그 들이다.

 

https://wg-cy.tistory.com/123

 

[Python활용] Chrome Driver 설치 및 Selenium 활용

안녕하세요 ! 이번 포스팅에서는 Python을 활용하기 위한 준비로 웹크롤링을 하기 위한 Chrome Driver 설치와 Selenium의 활용법에 대한 포스팅을 준비해보았습니다. Chrome Driver 설치 및 Selenium 활용 먼저

wg-cy.tistory.com

 

요약: 환경설정 옵션 수정

 

결과: 해결 X

 

환경 설정 > 보안 개인정보 보호 > 개인정보 보호 > 개발자 도구 > 터미널 옵션 체크(자물쇠 )

 

# 크롬드라이버 확인용 코드
from selenium import web driver
driver = web driver.Chrome(“[절대경로]”)

위 코드 치고 확인해보면 된다 했는데 내 경우는 안 됐다.

 

 

 

아래 블로그 덕분에 해결했다.

 

https://velog.io/@1yangsh/chromedriver-%EA%B0%9C%EB%B0%9C%EC%9E%90%EB%A5%BC-%ED%99%95%EC%9D%B8%ED%95%A0-%EC%88%98-%EC%97%86%EA%B8%B0-%EB%95%8C%EB%AC%B8%EC%97%90-chromedriver%EC%9D%84%EB%A5%BC-%EC%97%B4-%EC%88%98-%EC%97%86%EC%8A%B5%EB%8B%88%EB%8B%A4

 

[chromedriver] 개발자를 확인할 수 없기 때문에 'chromedriver'을(를) 열 수 없습니다.

chromedriver 에러

velog.io

 

 

작동시킬 프로젝트 폴더 경로에 들어가서

아래 코드를 치고 크롬 드라이버 확인용 코드를 쳐서 잘 됐는지 보면 된다.

xatter -d com.apple.quarantine chromedriver