Set chrome browser binary through chromedriver in Python
You can set Chrome Browser Binary location through ChromeDriver using Python ing the following different ways:
Using Options
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
driver = webdriver.Chrome(chrome_options=options, executable_path="C:/Utility/BrowserDrivers/chromedriver.exe", )
driver.get('http://google.com/')
Using DesiredCapabilities
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities.CHROME
cap = {'binary_location': "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"}
driver = webdriver.Chrome(desired_capabilities=cap, executable_path="C:\\Utility\\BrowserDrivers\\chromedriver.exe")
driver.get('http://google.com/')
Using Chrome as a Service
from selenium import webdriver
import selenium.webdriver.chrome.service as service
service = service.Service('C:\\Utility\\BrowserDrivers\\chromedriver.exe')
service.start()
capabilities = {'chrome.binary': "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"}
driver = webdriver.Remote(service.service_url, capabilities)
driver.get('http://www.google.com')
Thanks a lot I was struggling with this for 2.5 hours as I did not know how to set the Chrome Executable path in Python. Works now
options = Options()
options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
driver = webdriver.Chrome(chrome_options=options, executable_path="C:/Utility/BrowserDrivers/chromedriver.exe", )