pythonmacosselenium-webdrivermacos-catalinabrave-browser

How to use Brave web browser with Selenium on Catalina?


https://www.codegrepper.com/code-examples/python/python+selenium+brave+browser

I see this example to use brave browser on windows. Is it supposed to work on Catalina as well by just replacing driver_path and brave_path?

Also, Chromedriver is only for Chrome. How to determine which version of chromedriver should be used for brave browser?

https://chromedriver.chromium.org

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")

Solution

  • Prerequisites:
    Your chromedriver version should match your Brave Browser web driver version.

    To make sure it does:

    Finally run the following code (replace paths with ones on your machine if they are different):

    from selenium import webdriver  
    driverPath = '/usr/local/Caskroom/chromedriver/89.0.4389.23/chromedriver'
    binaryPath = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
    options = webdriver.ChromeOptions()
    options.binary_location = binaryPath
    browser = webdriver.Chrome(executable_path=driverPath, options=options)
    browser.get("https://www.google.com")
    

    If you have never used chromedriver before, after runnning the code you should see a macOS prompt saying that chromedriver is from unknown developer or was downloaded from the internet, smth like that. Close that prompt (It's important that you do this before moving on). Then go to System Preferences -> Security & Privacy -> press the lock icon and unlock it and then approve chromedriver to run on your machine. Run the above code again, a new macOS prompt will appear saying smth about unknown developer again, this time you can just click Open. Brave Browser window should pop up at this point. At least it did on my machine.
    P.S. I apologise for possibly going into too much detail, but sometimes i get really frustrated with answers which skip parts which are considered to be obvious