Home >Backend Development >Python Tutorial >Why Does Selenium Throw a `NoSuchDriverException` and How Can I Fix It?
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'
The problematic code appears as follows:
from selenium import webdriver chrome_driver_path = <chrome drive .exe path> driver = webdriver.Chrome(chrome_driver_path)
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()
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!