본문 바로가기

TroubleShooting/Python

'ChromeOptions' object has no attribute 'headless' 해결

728x90
> py app.py
'ChromeOptions' object has no attribute 'headless'
Traceback (most recent call last):
  File "D:\MyWork\python\app.py", line 32, in <module>
    driver.get(link)
AttributeError: 'NoneType' object has no attribute 'get'

 

사용 버전
> pip list
selenium                               4.15.2
undetected-chromedriver     3.5.3

 

undetected-chromedriver 패키지를 사용한 프로그램을 실행하려고 하니깐 headless 속성이 없다고 나온다.

 

selenium 4.13 부터 headless 가 지원이 안된다고 한다. (https://pypi.org/project/selenium/#history) 

혹시나 해서 4.12 로 다운그레이드해도 ChromeDriver 버전이 안맞다고 하면서 아래 오류가 발생한다. 

Message: unknown error: cannot connect to chrome at 127.0.0.1:61416
from session not created: This version of ChromeDriver only supports Chrome version 119
Current browser version is 117.0.5938.150
Stacktrace:
        GetHandleVerifier [0x007172A3+45731]
        ...

 

해당 크롬드라이버를 설치하려고 해도 117 은 크롬 드라이버 다운로드 사이트(https://chromedriver.chromium.org/downloads/version-selection) 에서는 찾을 수가 없다.

 

해결 방법은 https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/1584 를 참고했다.

options = uc.ChromeOptions()
options.headless = False
driver = uc.Chrome(options=options,version_main=116)

driver.get("https://google.com")

 

참고

https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/1584