————————————————————————— AttributeError Traceback (most recent call last) File ~anaconda3libsite-packagesseleniumwebdrivercommondriver_finder.py:38, in DriverFinder.get_path(service, options) 37 try: —> 38 path = SeleniumManager().driver_location(options) if path is None else path 39 except Exception as err: File ~anaconda3libsite-packagesseleniumwebdrivercommonselenium_manager.py:87, in SeleniumManager.driver_location(self, options) 80 “””Determines the path of the correct driver. 81 82 :Args: 83 – browser: which browser to get the driver path for. 84 :Returns: The driver path to use 85 “”” —> 87 browser = options.capabilities[“browserName”] 89 args = [str(self.get_binary()), “–browser”, browser] AttributeError: ‘str’ object has no attribute ‘capabilities’ During handling of the above exception, another exception occurred: AttributeError Traceback (most recent call last) Cell In[167], line 14 8 chrome_options.add_argument(“–headless”) # headlessモードを有効にする 9 # ChromeDriverのパスを取得 10 # chrome_driver_path = ChromeDriverManager().install() 11 12 # ChromeDriverを起動 13 # driver = webdriver.Chrome(options=chrome_options) —> 14 driver = webdriver.Chrome(ChromeDriverManager().install()) 15 # options = webdriver.ChromeOptions() 16 # options.add_argument(“–headless”) # ヘッドレスモードでChromeを起動する場合 17 # driver = webdriver.Chrome(ChromeDriverManager().install()) 18 19 20 # ログイン 21 login(driver,login_url,login_id,login_pass) File ~anaconda3libsite-packagesseleniumwebdriverchromewebdriver.py:45, in WebDriver.__init__(self, options, service, keep_alive) 42 service = service if service else Service() 43 options = options if options else Options() —> 45 super().__init__( 46 browser_name=DesiredCapabilities.CHROME[“browserName”], 47 vendor_prefix=”goog”, 48 options=options, 49 service=service, 50 keep_alive=keep_alive, 51 ) File ~anaconda3libsite-packagesseleniumwebdriverchromiumwebdriver.py:49, in ChromiumDriver.__init__(self, browser_name, vendor_prefix, options, service, keep_alive) 37 “””Creates a new WebDriver instance of the ChromiumDriver. Starts the 38 service and then creates new WebDriver instance of ChromiumDriver. 39 (…) 45 – keep_alive – Whether to configure ChromiumRemoteConnection to use HTTP keep-alive. 46 “”” 47 self.service = service —> 49 self.service.path = DriverFinder.get_path(self.service, options) 50 self.service.start() 52 executor = ChromiumRemoteConnection( 53 remote_server_addr=self.service.service_url, 54 browser_name=browser_name, (…) 57 ignore_proxy=options._ignore_local_proxy, 58 ) File ~anaconda3libsite-packagesseleniumwebdrivercommondriver_finder.py:40, in DriverFinder.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 43 if path is None or not Path(path).is_file(): AttributeError: ‘str’ object has no attribute ‘capabilities’
このエラーは、ChromeDriverManagerがSelenium Managerを使用してChromeDriverのパスを取得しようとする際に発生しています。このエラーは、Selenium Managerがoptionsオブジェクトからブラウザ名を取得する際に失敗していることを示しています。
問題の解決には、次のようなアプローチを試すことができます:
-
ChromeDriverManagerのバージョンを確認して更新する。古いバージョンのChromeDriverManagerを使用している場合、この問題が発生する可能性があります。最新のバージョンに更新してみてください。
-
ChromeDriverManagerの代わりに、直接ChromeDriverのパスを指定する。次のようにChromeDriverのパスを直接指定してChromeDriverを起動してみてください。
python
from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--headless") # headlessモードを有効にする chrome_driver_path = "/path/to/chromedriver" # ChromeDriverのパスを指定 driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)
この方法では、ChromeDriverのパスを手動で指定するため、ChromeDriverManagerを使用する必要はありません。
- Selenium Managerが正しく構成されているかどうかを確認する。Selenium Managerの設定に問題がある場合、このエラーが発生する可能性があります。Selenium Managerのドキュメントを参照して、正しく構成されているかどうかを確認してください。
これらのアプローチを試してみてください。それでも問題が解決しない場合は、追加の情報が必要になるかもしれません。

ディスカッション
コメント一覧
まだ、コメントがありません