반응형
AttributeError: 'str' object has no attribute 'capabilities'¶
- 현재
selenium
은 크롬드라이브를 따로 다운받지 않아도 사용할 수 있는 기능을 제공하고 있습니다. - 아래 코드와 같이
'./chromedriver'
를 불러오면 에러가 발생합니다.
from selenium import webdriver
driver = webdriver.Chrome('./chromedriver')
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) ~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/common/driver_finder.py in get_path(service, options) 37 try: ---> 38 path = SeleniumManager().driver_location(options) if path is None else path 39 except Exception as err: ~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/common/selenium_manager.py in driver_location(self, options) 75 ---> 76 browser = options.capabilities["browserName"] 77 AttributeError: 'str' object has no attribute 'capabilities' During handling of the above exception, another exception occurred: AttributeError Traceback (most recent call last) <ipython-input-6-c2e9cad52997> in <module> ----> 1 driver = webdriver.Chrome('./chromedriver') ~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, options, service, keep_alive) 43 options = options if options else Options() 44 ---> 45 super().__init__( 46 DesiredCapabilities.CHROME["browserName"], 47 "goog", ~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py in __init__(self, browser_name, vendor_prefix, options, service, keep_alive) 49 self.service = service 50 ---> 51 self.service.path = DriverFinder.get_path(self.service, options) 52 53 self.service.start() ~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/common/driver_finder.py in get_path(service, options) 38 path = SeleniumManager().driver_location(options) if path is None else path 39 except Exception as err: ---> 40 msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager." 41 raise NoSuchDriverException(msg) from err 42 AttributeError: 'str' object has no attribute 'capabilities'
- 아래와 같이
'./chromedriver'
를 제거 하면 바로 사용할 수 있습니다.
driver = webdriver.Chrome()
반응형
'python' 카테고리의 다른 글
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 0: invalid start byte (0) | 2023.09.18 |
---|---|
TypeError: unsupported operand type(s) for +: 'int' and 'str' (0) | 2023.09.18 |
파이썬 튜플을 csv로 (tuple to csv) (0) | 2023.09.04 |
파이토치 정수 랜덤 생성 (0) | 2023.08.29 |
파이토치 손실함수 Cross Entropy Loss (0) | 2023.08.29 |
댓글