플그래밍/파이써언

[파이썬 에러] DeprecationWarning: executable_path has been deprecated, please pass in a Service object

훗티v 2022. 11. 10. 16:40
728x90
반응형

0. 에러

DeprecationWarning: executable_path has been deprecated, please pass in a Service object
이번 Selenium 4.0 업데이트로 인해 발생하는 에러입니다.

 

🔗 Selenium 4.0 Beta 1 changelog

 

1. 업데이트 및 모듈 추가

pip3 install -U selenium

pip3 install webdriver-manager
셀레니움 4.0 이상 버젼으로 설치
webdriver-manager 설치

 

# BEFORE
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
# AFTER
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
맨 아래 세 항목을 기존 코드에 추가합니다.

 

2. 코드 변경

# BEFORE
driver = webdriver.Chrome(r'c:\chromedriver', options=option)
# AFTER
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=option)
크롬드라이버 경로를 위와 같이 변경해줍니다.

 

 

 

 

 

 

반응형