I tried to fix the above error by check Stackoverflow and other resources from the internet. But I am getting the error. I have installed the webdriver_manager also. But i could not able to run the code. I am using kubuntu, pycharm. Below is my code and its error.
from selenium import webdriver
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
'''from webdriver_manager.chrome import ChromeDriverManager
driver.implicitly_wait(0.5)
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
#driver = webdriver.Chrome(ChromeDriverManager().install())'''
driver = webdriver.Chrome()
#driver = webdriver.Chrome(executable_path="/home/halovivek/Documents/Automation/selenium_driver/chromedriver.exe")
#driver = webdriver.Chrome()"
driver.maximize_window()
driver.get("https://www.google.com")
Below is my error message:-
/home/halovivek/PycharmProjects/pythonProject/venv/bin/python /home/halovivek/PycharmProjects/pythonProject/Test.py
====== WebDriver manager ======
Current google-chrome version is 98.0.4758
Get LATEST chromedriver version for 98.0.4758 google-chrome
Driver [/home/halovivek/.wdm/drivers/chromedriver/linux64/98.0.4758.102/chromedriver] found in cache
/home/halovivek/PycharmProjects/pythonProject/Test.py:4: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(ChromeDriverManager().install())
Traceback (most recent call last):
File "/home/halovivek/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 71, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/halovivek/PycharmProjects/pythonProject/Test.py", line 16, in <module>
driver = webdriver.Chrome()
File "/home/halovivek/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/home/halovivek/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 90, in __init__
self.service.start()
File "/home/halovivek/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
Process finished with exit code 1
Please help me to find the solution
CodePudding user response:
The error is
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
Solution is:
s = Service('/home/halovivek/Documents/Automation/selenium_driver/chromedriver.exe')
driver = webdriver.Chrome(service = s)
driver.maximize_window()
driver.get("https://www.google.com")
Make sure to download latest version of chromedriver from here
Imports:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
CodePudding user response:
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
Have to use them in conjuction since executable path has been depreciated.