Thursday, October 5, 2023

Selenium execution on brave browser

Selenium WebDriver is a popular tool for automating web browsers, but it might not have direct support for the Brave browser, as it primarily focuses on mainstream browsers like Google Chrome, Mozilla Firefox, Microsoft Edge, etc. However, you can still automate the Brave browser by following these general steps:


Install Brave Browser: Make sure you have Brave Browser installed on your system. You can download it from the official Brave website.


Download WebDriver for Chrome: Since Brave is based on Chromium (the same open-source project that Google Chrome is built on), you can use the Chrome WebDriver for automating Brave. Download the appropriate version of the Chrome WebDriver for your Brave Browser version.


Set Up Selenium: You'll need to set up a Selenium project in your preferred programming language (e.g., Python, Java, etc.). You can install Selenium using a package manager like pip (for Python) or Maven (for Java).


Write Selenium Code: Use Selenium's API to write automation scripts. Here's an example using Python:


from selenium import webdriver

# Set the path to your Chrome WebDriver executable
webdriver_path = '/path/to/chromedriver'

# Configure Brave options
brave_options = webdriver.ChromeOptions()
brave_options.binary_location = '/path/to/brave-browser'

# Initialize the WebDriver with Brave options
driver = webdriver.Chrome(executable_path=webdriver_path, options=brave_options)

# Now you can use Selenium to interact with the Brave browser
driver.get('https://www.example.com')
# Perform actions like clicking buttons, filling forms, etc.

# Close the browser when done
driver.quit()

Make sure to replace '/path/to/chromedriver' and '/path/to/brave-browser' with the actual paths to your Chrome WebDriver executable and Brave Browser binary.


Please note that the compatibility of Selenium WebDriver and Brave Browser may change over time, so it's a good idea to check the latest documentation and community resources for any updates or specific support for Brave. Additionally, the directory paths and WebDriver versions may have changed since my last update, so you should verify those details accordingly.

We can still use the Service object we used for other browsers in this link
See below code for reference

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

service_obj = Service()

# Configure Brave options
brave_options = webdriver.ChromeOptions()
brave_options.binary_location = r"C:\Users\UReddy\AppData\Local\BraveSoftware\Brave-Browser\Application\brave.exe"

driver=webdriver.Chrome(service=service_obj, options=brave_options)

driver.maximize_window()
driver.get("https://google.com")
print(driver.title)
print(driver.current_url)
driver.get("https://bing.com/#/")
#driver.minimize_window()
driver.back()
driver.refresh()
driver.forward()
driver.close()

No comments:

Post a Comment