Issue
Getting the following error when trying to create object with Selenium Webdriver.
"\selenium\webdriver\common\driver_finder.py", line 42, in get_path
path = SeleniumManager().driver_location(options) if path is None else path
"\selenium\webdriver\common\selenium_manager.py", line 74, in driver_location
browser = options.capabilities["browserName"]
AttributeError: 'str' object has no attribute 'capabilities'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
"\selenium_webdriver_webscraping.py", line 4, in <module>
driver = webdriver.Chrome(chrome_driver_path)
"\selenium\webdriver\chrome\webdriver.py", line 47, in __init__
self.service.path = DriverFinder.get_path(self.service, self.options)
"\selenium\webdriver\common\driver_finder.py", line 44, in get_path
raise NoSuchDriverException(f"Unable to obtain {service.path} using Selenium Manager; {err}")
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain chromedriver using Selenium Manager; 'str' object has no attribute 'capabilities'; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
This is the code I used:
from selenium import webdriver
chrome_driver_path = <chrome drive .exe path>
driver = webdriver.Chrome(chrome_driver_path)
Solution
If the selenium version you are using is v4.6.0
or above (which I think it is as I see SeleniumManger
in the error trace), then you don't really have to set the driver.exe
path. Selenium can handle the browser and drivers by itself.
So your code can be simplified as below:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com/")
driver.quit()
Few references:
Answered By - Shawn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.