All Posts

How to fix unexpected keyword ‘executable_path’

How to fix unexpected keyword ‘executable_path’

The following is the error trace. Let’s understand the error and learn how to fix this error in Python automation scripts.

Error trace:

TypeError: WebDriver.__init__() got an unexpected
keyword argument ‘executable_path‘

 

WebDriver Unexpected Keyword Executable Path

Example

For example, the following Python Selenium test code will throw this particular

error:

# Python Selenium Script
# Python Selenium Tutorials
# www.TestingDocs.com 

from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest

class login(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome(executable_path='
D:\chromedriver.exe')
        self.base_url = "https://www.google.com"
        
    def test_example(self):
        driver = self.driver
        driver.get(self.base_url)
        driver.find_element(By.NAME,"q").send_keys("test")
     
    def tearDown(self):
        self.driver.quit()
        
        
if __name__ == '__main__':
    unittest.main()          

Fix

This error occurs because of the webdriver.Chrome class in Selenium no longer accepts the executable_path argument in its initializer. Instead, you should use the webdriver.Chrome with the Service object to specify the path to the ChromeDriver executable.

fixed code:

self.driver = w