Home > Backend Development > Python Tutorial > Why Does Selenium Throw a `NoSuchDriverException` and How Can I Fix It?

Why Does Selenium Throw a `NoSuchDriverException` and How Can I Fix It?

Susan Sarandon
Release: 2024-12-10 17:55:15
Original
191 people have browsed it

Why Does Selenium Throw a `NoSuchDriverException` and How Can I Fix It?

Unable to Use Selenium Webdriver: Two Exceptions

In an attempt to create an object using Selenium Webdriver, the following error surfaces:

AttributeError: 'str' object has no attribute 'capabilities'

During handling of the above exception, another exception occurred:

selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain chromedriver using Selenium Manager; 'str' object has no attribute 'capabilities'
Copy after login

Examining the Code

The problematic code appears as follows:

from selenium import webdriver

chrome_driver_path = <chrome drive .exe path>
driver = webdriver.Chrome(chrome_driver_path)
Copy after login

Simplifying the Solution

For Selenium versions v4.6.0 and above, explicitly specifying the driver location is obsolete. Selenium can manage the browser and drivers independently. Therefore, the code can be simplified to:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.google.com/")
driver.quit()
Copy after login

Understanding Selenium Manager

Selenium Manager automates the location and retrieval of webdriver binaries, making it unnecessary to specify the driver location manually. This feature simplifies the Selenium setup process, particularly for versions v4.6.0 and higher.

The above is the detailed content of Why Does Selenium Throw a `NoSuchDriverException` and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template