I am trying to setup a hello world app to learn Selenium. I want to write a script that opens the Brave web browser.
I tried a few code scripts online and at Stack overflow and nothing seems to work.
const { Builder } = require("selenium-webdriver")
async function example() {
let driver = await new Builder().forBrowser("brave").build();
console.log(driver)
await driver.get("https://www.youtube.com/");
}
example();
The above script does not recognize brave so I changed forBrowser("brave) to "chrome". It still doesn't work.
I found the following code online that allows me to get the exact directory of the browser I want to launch, but I do not know how to combine it with what I already have.
const chrome = require('selenium-webdriver/chrome');
chrome.setDefaultService(new chrome.ServiceBuilder('/usr/share/applications/google-chrome.desktop').build());
I read the code below at another thread but I am not sure how to launch a browser instance using it.
const chrome = require('selenium-webdriver/chrome')
const chromeOptions = new chrome.Options()
chromeOptions.setChromeBinaryPath('/usr/bin/brave-browser')
EDIT
The code below is my latest attempt at cobbling together methods from around the web to make this work.
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const chromeOptions = new chrome.Options()
chromeOptions.setChromeBinaryPath('/home/wktdev/Desktop/selenium/drivers/chrome/chromedriver')
let driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(chromeOptions)
.build();
driver.get('http://example.com');
I get an error saying "Error: The ChromeDriver could not be found on the current PATH. "
I am unsure how to proceed
EDIT I have Chrome launching. Here is what I did:
I updated to the latest Chrome Browser. I downloaded the newest chrome driver that mirrors my version of Chrome here:
https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/
I created a random directory on the desktop such as blah/code and I put the downloaded files there.
I then opened a terminal window and added that directory to my computers path variable like this:
export PATH=$PATH:/some/new/path
I kept the current terminal window open and rand the node.js script and chrome opened.
I now need to know how to change this so that it opens Brave instead