Run Selenium Tests on Brave Browser: Step-by-Step
In this article
Running Selenium tests on the Brave browser is nearly identical to testing on Chrome, because Brave is built on the same Chromium engine. This guide shows you how to configure Selenium WebDriver to launch Brave, execute your tests, and avoid common pitfalls. You'll need a basic understanding of Selenium and a programming language like Python, Java, or JavaScript.
What You'll Need
- Brave Browser installed on your machine (any recent version).
- Selenium WebDriver installed for your preferred language (e.g.,
seleniumPython package,selenium-java, orselenium-webdrivernpm package). - ChromeDriver – the WebDriver executable that controls Chromium-based browsers. You can download it from the Chrome for Testing site or use a driver manager like
webdriver-manager(Python) orchromedrivernpm package. - A code editor and a test project set up.
Step-by-Step
- Install Selenium and a driver manager (optional but recommended). For Python:
pip install selenium webdriver-manager. For Node.js:npm install selenium-webdriver chromedriver. For Java: add Selenium and WebDriverManager dependencies via Maven or Gradle. - Locate your Brave executable path. On Windows, it's typically
C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe. On macOS:/Applications/Brave Browser.app/Contents/MacOS/Brave Browser. On Linux:/usr/bin/brave-browseror/opt/brave.com/brave/brave. If unsure, runwhich brave-browseron Linux/macOS or check the Start Menu shortcut on Windows. - Set the browser binary path in your Selenium options. In Python, use
options.binary_location = "path/to/brave". In Java,options.setBinary("path/to/brave"). In JavaScript,options.setChromeBinaryPath("path/to/brave"). - Create ChromeOptions (or equivalent) and pass them to the driver. Since Brave is Chromium-based, you use ChromeOptions. Example in Python:
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.binary_location = "/usr/bin/brave-browser" driver = webdriver.Chrome(options=options)In Java:ChromeOptions options = new ChromeOptions(); options.setBinary("/usr/bin/brave-browser"); WebDriver driver = new ChromeDriver(options);In JavaScript:const { Builder } = require('selenium-webdriver'); const chrome = require('selenium-webdriver/chrome'); let options = new chrome.Options(); options.setChromeBinaryPath('/usr/bin/brave-browser'); let driver = new Builder().forBrowser('chrome').setChromeOptions(options).build(); - Run your test script. The driver will launch Brave instead of Chrome. Write your test code as usual – find elements, interact, assert. For example, open a website and check its title.
- Close the driver after tests. Always call
driver.quit()to release resources and close the browser window.
Common Mistakes
- Forgetting to set the binary location. Without it, Selenium launches Chrome, not Brave. Double-check the path is correct.
- Using an outdated ChromeDriver. Brave and Chrome share the same Chromium version, but if your ChromeDriver is too old or too new, it may fail to communicate with the browser. Match the major version of ChromeDriver to the Chromium version used by your Brave installation.
- Assuming Brave is exactly Chrome. While it's Chromium-based, Brave has its own default settings (e.g., shields, privacy features) that might affect tests. Disable shields if they interfere with page loading or element visibility.
- Hardcoding paths. Paths differ across OS and installations. Use environment variables or a config file to make tests portable.
Tips
- Use a driver manager. Tools like
webdriver-manager(Python) orWebDriverManager(Java) automatically download the correct ChromeDriver version, saving you from manual updates. - Run headless if needed. Add
options.add_argument("--headless")to run tests without a visible browser window, useful for CI/CD. - Disable Brave shields for consistent behavior. You can add
options.add_argument("--disable-brave-shields")or set the preferencebrave.shields.enabledto false viaoptions.add_experimental_option("prefs", {"brave.shields.enabled": False})in Python. - Use a dedicated test profile. Create a separate user data directory to avoid interference from your personal Brave profile. Add
options.add_argument("--user-data-dir=/path/to/test-profile"). - Check the browser version. In Brave, go to
brave://versionto see the Chromium version. Ensure your ChromeDriver matches that major version.
Troubleshooting
- “ChromeDriver cannot be found” error. Ensure the ChromeDriver executable is in your PATH or specify its location via the
webdriver.chrome.driversystem property (Java) orexecutable_pathparameter (Python). - “SessionNotCreatedException: This version of ChromeDriver only supports Chrome version X” – Your ChromeDriver version doesn't match Brave's Chromium version. Update ChromeDriver to the version that matches the Chromium version shown in
brave://version. - Brave opens but tests fail to find elements. This could be due to Brave Shields blocking scripts or elements. Disable shields as described in Tips. Also, wait for elements to be present using explicit waits (
WebDriverWait). - “Unable to start the browser” or crash on launch. Verify the binary path is correct and that you have permission to execute it. Also, try running Brave manually to ensure it opens normally.
- Tests work on Chrome but not Brave. Compare the browser versions. If Brave is behind Chrome, use an older ChromeDriver. Alternatively, update Brave to the latest version.
Frequently Asked Questions
Do I need a separate WebDriver for Brave?
No. Brave uses the same ChromeDriver as Chrome because it's built on Chromium. You just need to point Selenium to the Brave executable.
Can I run tests on Brave without changing my existing Chrome tests?
Yes, if your tests use ChromeOptions. Simply add the binary location to point to Brave. However, be aware that Brave's default settings (like shields) might cause differences, so test thoroughly.
Is Brave compatible with all Selenium features?
Yes, since it's Chromium-based, all standard Selenium WebDriver commands work. Some features like browser extensions might behave differently, but core functionality is the same.
How do I find the correct ChromeDriver version for Brave?
Check the Chromium version in brave://version (e.g., 120.0.6099.109). Then download ChromeDriver from the Chrome for Testing site that matches that major version (e.g., 120.x).
Can I run Brave tests in headless mode?
Yes. Add the --headless argument to ChromeOptions. Note that some features like extensions may not work in headless, but basic tests will run.
What if my Brave installation is not in the default location?
Use the full path to the executable in your code. You can find it by right-clicking the Brave shortcut and selecting “Open file location” (Windows) or using which brave-browser on Linux/macOS.