11

I switched from Google's Chrome to Brave web browser and am having a hard time getting it to work with Brave like it did with Chrome. Brave is based on chromium so I guessed it should not be that hard. I made sure that my Brave and Chromedriver are on the same version like this,

~/some/path $ chromedriver --version
ChromeDriver 76.0.3809.126 (d80a294506b4c9d18015e755cee48f953ddc3f2f-refs/branch-heads/3809@{#1024})

My chromedriver is also in /user/bin,

~/path $ cd /usr/bin/
/usr/bin $ ls | grep chromedriver
chromedriver 

And to check the Brave version, I get: Version 0.68.132 Chromium: 76.0.3809.132 (Official Build) (64-bit)

Then I run this code,

from selenium import webdriver

driver = webdriver.Chrome(executable_path='/usr/bin/brave-browser')
driver.get("http://www.python.org")
driver.close()

This opens a Brave window but then instead of getting the page the driver is pointed to, an exception is thrown,

Traceback (most recent call last):
  File "webscrap.py", line 3, in <module>
    driver = webdriver.Chrome(executable_path='/usr/bin/brave-browser')
  File "/home/username/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/home/username/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/username/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/brave-browser unexpectedly exited. Status code was: -11
scribe
  • 673
  • 2
  • 6
  • 17

4 Answers4

33

I finally managed to make it work:

Try this python script (python3.7)

from selenium import webdriver

driver_path = "C:/Users/username/PycharmProjects/chromedriver.exe"
brave_path = "C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"

option = webdriver.ChromeOptions()
option.binary_location = brave_path
# option.add_argument("--incognito") OPTIONAL
# option.add_argument("--headless") OPTIONAL

# Create new Instance of Chrome
browser = webdriver.Chrome(executable_path=driver_path, chrome_options=option)

browser.get("https://www.google.es")

cheers.

Ricael
  • 346
  • 3
  • 6
8

The executable_path key is used to pass the absolute path of the WebDriver binary i.e. the chromedriver executable.

To initiate a Brave browser session additionally you have to pass the absolute location of the brave-browser binary through the binary_location argument of an instance of ChromeOptions.

So the effective code block will be:

from selenium import webdriver

chromedriver_path = '/usr/bin/chromedriver'
brave_path = '/usr/bin/brave-browser'
option = webdriver.ChromeOptions()
option.binary_location = brave_path
browser = webdriver.Chrome(executable_path=driver_path, options=option)
browser.get("https://www.google.es")

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
2

This also works in windows 10 with Brave browser. I downloaded Chromedriver and put it in the folder with Brave.exe.

from selenium import webdriver
driver_path = "C:\\Users\\5150s\\AppData\\Local\\Programs\\Python\\Python38\\chromedriver.exe"
brave_path = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
option = webdriver.ChromeOptions()
option.binary_location = brave_path
browser = webdriver.Chrome(executable_path=driver_path, options=option)
browser.get("https://www.google.es")
Calvin
  • 21
  • 1
  • Make sure to download the driver that matches your Brave browser. Go to "About Brave" and look for the Chromium driver version, e.g. Chromium: 91.0.4472.164, then select that version from the Chromium download site: https://chromedriver.chromium.org/downloads. – Thane Plummer Jul 20 '21 at 21:05
0

The solutions above gave me some errors. This code removes the executable path and options errors. Chromedriver is in the pycharm folder.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

driver_path = "C:/Users/johnm/PycharmProjects/chromedriver.exe"
brave_path = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"

s=Service(driver_path)
option = webdriver.ChromeOptions()
option.binary_location = brave_path
browser = webdriver.Chrome(service=s, options=option)
browser.get("https://www.google.es")