How to run Selenium tests on the Brave web browser?
Asked Answered
C

7

31

I am trying to run some Selenium tests on the Brave web browser. I am able to start the Brave web browser through Selenium by using the ChromeDriver. However, nothing else works, e.g. I cannot cause Brave to load a certain web page.

As Brave is based on Chromium, I would think this is the way to go. Are there more appropriate ways that support Brave to be driven by Selenium?

This is de code that I used:

    ChromeOptions options = new ChromeOptions().setBinary("/Applications/Brave.app/Contents/MacOS/brave");
    WebDriver driver = new ChromeDriver(options);
Clay answered 7/11, 2017 at 12:47 Comment(4)
Could you add more details on how did you made the webdriver start Brave? I'm trying to do something similar and looking for details.Othella
I used the following line to use the Brave binary for the ChromeDriver: ChromeOptions options = new ChromeOptions().setBinary("/path/to/brave/executable");Clay
Did you really get it to load? I see an exception when I try: System.InvalidOperationException occurred HResult=0x80131509 Message=unknown error: no chrome binary at C:\SOMEPATH\Brave64\app-0.22.22\brave.exe (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 6.1.7601 SP1 x86_64) Source=WebDriver StackTrace: at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at....[and this goes on for a while]Juta
Yes, I managed to load Brave, but that's it. Did it on MacOS though, not sure if the path has something to do with it.Clay
C
15

For the record: this is no longer an issue since Brave went full-Chromium (starting from version 0.57). I can now pass instructions to the WebDriver by initializing it using the code snippet included in the question.

Nevertheless, be sure to check that your ChromeDriver version is compatible with your Brave Browser version.

Clay answered 29/4, 2019 at 10:7 Comment(2)
Thanks Barney. For others, please note that as of Brave Version 0.64.77 Chromium: 74.0.3729.169 you have to mach Chromium Version with ChromeDriver Version (in this case ChromeDriver 74.0.3729.6) and the .SetBinary() method changed to .BinaryLocation property that you can get & set before calling the constructor of ChromeDriver() with the options object.Unmitigated
@PetruZaharia Your comment need to be part of an answerJurywoman
O
11

System:
macOS Catalina 10.15.2
Python 3.7.4
pytest 5.3.2
selenium 3.141.0
ChromeDriver 79.0.3945.36
Brave 1.1.23 Chromium: 79.0.3945.88 (Official Build) (64-bit)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
driver_path = '/usr/local/bin/chromedriver'
drvr = webdriver.Chrome(options = options, executable_path = driver_path)
drvr.get('https://stackoverflow.com')

Reference:
Set chrome browser binary through chromedriver in Python

Osbourn answered 23/12, 2019 at 9:28 Comment(1)
I have similar issue. Some days ago I changed my browser Chrome to Brave. So I uninstalled Chrome, but my script refered to chromedriver. ¿Is the same method ? I'm using Ubuntu 18.04 and AnacondaPretence
F
2

for windows user path must be absolute in your case

System.setProperty("webdriver.chrome.driver","E:\\WEBDRIVER PLUGINS\\chromedriver_win32\\chromedriver.exe");
ChromeOptions options = new ChromeOptions().setBinary("C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe");
WebDriver driver = new ChromeDriver(options);
Foment answered 6/1, 2020 at 16:59 Comment(0)
I
1

Thanks, @BarneyKelly, works like a charm! In python3 (Linux Mint 2020) I used:

def abre_navegador(self):
    # Avenue_Basico.wd = webdriver.Firefox()   # Criar instância do navegador 
    # Avenue_Basico.wd = webdriver.Chrome()   # Criar instância do navegador

    options = Options()
    options.binary_location = '/usr/bin/brave-browser'
    driver_path = '/usr/local/bin/chromedriver'
    self.wd = webdriver.Chrome(options = options, executable_path = driver_path)

Again, Thank You for your help.

Inebriety answered 27/7, 2020 at 13:23 Comment(0)
P
0

I was unable to find success with the above examples, though I did manage to get it working like so:

const chrome = require('selenium-webdriver/chrome')

const chromeOptions = new chrome.Options()

chromeOptions.setChromeBinaryPath('/usr/bin/brave-browser')
Prospect answered 5/11, 2021 at 14:41 Comment(1)
Do you have an example of using this with all the basic code needed to launch a browser instance? I am trying to get this working as a "hello world" app and I am unsure how to incorporate your code. Thank you!Pavid
S
0

for java and linux users:

    System.setProperty("webdriver.chrome.driver","src/chromedriver");

    ChromeOptions options = new ChromeOptions();

    options.setBinary("/usr/bin/brave-browser");
    options.addArguments("--start-maximized");
    options.addArguments("--disable-extensions");
    options.addArguments("--disable-gpu ");
    options.addArguments("--no-sandbox");

    WebDriver driver=new ChromeDriver(options);
    driver.get("https://www.yourlinkhere.com");
Spongy answered 28/7, 2022 at 6:52 Comment(0)
A
0

This will work for python:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = r"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe"

driver = webdriver.Chrome(options=chrome_options)
Ayr answered 14/11, 2023 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.