python
AttributeError: 'str' object has no attribute 'capabilities'
타닥타닥 토다토닥 부부
2023. 9. 13. 23:56
반응형
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()
반응형