Issue
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.google.com")
driver.quit()
When I try to run this code, I get an error like this:
AttributeError: 'str' object has no attribute 'capabilities' in "driver = webdriver.Chrome(ChromeDriverManager().install())"
I was try open google with selenium but I cant open I cant fix it.
Solution
You need to use Service Class in the latest selenium versions to pass the driver executable path or ChromeDriverManager
setup. See code below.
Change your code as below:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://www.google.com")
driver.quit()
SUGGESTION: If you are using latest selenium version, there is a more easy way to handle browser drivers. You don't need third party libraries like ChromeDriverManager
. Selenium's built-in tool Selenium Manager can do what ChromeDriverManager
used to do.
Code can be as simple as:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
driver.quit()
Answered By - Shawn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.